IntroductionHere are some features from Laravel that you may not be aware of.
Here are a few examples: public function user ( ) { return $this -> belongsTo ( 'App\User' ) -> withDefault ( ) ; } //or public function user ( ) { return $this -> belongsTo ( 'App\User' ) -> withDefault ( [ 'name' => 'Guest Author' , ] ) ; } // or public function user ( ) { return $this -> belongsTo ( 'App\User' ) -> withDefault ( function ( $user ) { $user -> name = 'Guest Author' ; } ) ; } For the implenetation details check out SupportsDefaultModels.php .
View composers will bound data to a view every time that view file is rendered.
You can also decide to append data at run time like this: return $user -> append ( 'is_admin' ) -> toArray ( ) ; // or return $user -> setAppends ( [ 'is_admin' ] ) -> toArray ( ) ; See more here.
Please let me know in the comments if there are any useful features of Laravel that you think are underused, that I've not mentioned.