Model naming conventions will save you time If you use the naming conventions as stated in the documentation you will prevent a lot of boilerplate code https://laravel.com/docs/8.x/eloquent#table-names
requires: laravel >= 5.0

If you use the naming conventions as stated in the documentation you will prevent a lot of boilerplate code. In this example there is a table named venuereviewreplies , not meeting the Laravel naming conventions. If we rename the table to venue_reviw_replies we can unlock the power of the models and prevent boilerplate code

Original code




        
        App\Models;

        use Illuminate\Database\Eloquent\Model;

        class VenueReviewReply extends Model
        {
                 public $table = 'venuereviewreplies';

                 public function venuereview()
                 {
                     return $this->belongsTo('App\Models\VenueReview', 'venuereview_id');
                 }
        }
        


        

Refactored code



        
        namespace App\Models;

        use Illuminate\Database\Eloquent\Model;

        class VenueReviewReply extends Model
        {
                 public function venuereview()
                 {
                     return $this->belongsTo(VenueReview::class);
                 }
        }

       

       

Want to learn more from LLoadout ?

LLoadout is your loadout for Laravel, helping you kickstart your development process. Besides this refactoring site we also make some cool packages and video tutorials !

Go to LLoadout on github