Saturday, August 13, 2016

Laravel 5.2 Implicit model binding

In Laravel 5.2 new feature called implicit model binding added. Which can be implement efficiently and in a very easy manner. Here how its done :
  1. In your routes.php file create a new route
    Route::get('user',function(){});
  2. Now if you want to retrieve information of a particular user, modify your user route as follow
    Route::get('user/{user}',function(App\User $user){ return $user; 
    });
Now if you browse your defined route , localhost:8000/user/1
(Assuming your laravel application running on localhost, port 8000 and you have data on your user table)
This will return information in JSON format of the user who has id 1.
Here , App\User is the namespace for User model.

Related Posts:

  • Laravel 5.2 Implicit model binding In Laravel 5.2 new feature called implicit model binding added. Which can be implement efficiently and in a very easy manner. Here how its done : In your routes.php file create a new route Route::get('user',function(){}); … Read More
  • Laravel Elixir Setup and Uses Laravel Elixir provides a clean, fluent API for defining basic Gulp tasks for your Laravel application. Elixir supports several common CSS and JavaScript pre-processors, and even testing tools. Using method chaining, … Read More
  • Install LAMP and PHPmyAdmin && PHPpgAdmin on Ubuntu 14.04 Install LAMP Steps are: sudo apt-get update sudo apt-get install apache2 sudo apt-get install mysql-server php5-mysql sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt sudo gedit /etc/apache2/conf-available/serve-… Read More
  • Laravel 5.2 using queue to send email To sent email after desired number of second, first change the .env file as follow. First provide database credential set QUEUE_DRIVER=sync to QUEUE_DRIVER=database Normally , QUEUE_DRIVER=sync tries to sent email immedi… Read More
  • Laravel Project Setup Using Composer In this tutorial i’ll write the key points that are necessary to create a laravel project/setting a laravel project with the help of composer. Composer Setup First We have to understand what is composer? Well, Composer is … Read More

0 comments:

Post a Comment