Laravel: Difference between revisions

From Adam Colton
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
== Database Setup ==
== Implicit Route Binding ==
# Create the database
From [https://laracasts.com/series/whats-new-in-laravel-5-2/episodes/1 this] video
# Add database info in app/config/database.php
  Route::get('users/{user}', function(App\User $user){
# php artisan migrate:install
    return $user;
  });
If the arg name matches the token, it will magic that value into place. With the type hinting, it will find a user with the primary key given in the url.


To add a migration
To use something other than the primary key, you have to add a route binding in RouteServiceProvider.
  php artisan migrate:make migration_name
That file will appear in app/database/migrations
 
Note that $table->increments('id') automatically makes that the primary key.

Revision as of 21:52, 21 January 2016

Implicit Route Binding

From this video

 Route::get('users/{user}', function(App\User $user){
   return $user;
 });

If the arg name matches the token, it will magic that value into place. With the type hinting, it will find a user with the primary key given in the url.

To use something other than the primary key, you have to add a route binding in RouteServiceProvider.