Home » Laravel Tutorial (page 3)

Laravel Tutorial

Laravel – Redirections

Named route is used to give specific name to a route. The name can be assigned using the “as” array key. Route::get('user/profile', ['as' => 'profile', function () { // }]); Redirecting to Named Routes Example Observe the following example to understand more about Redirecting to named routes − Step 1 − Create a …

Read More »

Laravel – Blade Templates

Laravel 5.1 introduces the concept of using Blade, a templating engine to design a unique layout. The layout thus designed can be used by other views, and includes a consistent design and structure. When compared to other templating engines, Blade is unique in the following ways − It does not restrict …

Read More »

Laravel – Views

In MVC framework, the letter “V” stands for Views. It separates the application logic and the presentation logic. Views are stored in resources/views directory. Generally, the view contains the HTML which will be served by the application. Example Observe the following example to understand more about Views − Step 1 − Copy the following code and …

Read More »

Laravel – Response

Response can be sent either from route or from controller. This string will be automatically converted to appropriate HTTP response. Example Step 1 − Add the following code to app/Http/routes.php file. Route::get('/basic_response', function () { return 'Hello World'; }); Step 2 − Visit the following URL to test the basic response. http://localhost:8000/basic_response Step 3 − The output will …

Read More »

Laravel – Cookie

Cookies play an important role while dealing a user’s session on a web application. Cookie can be created by global cookie helper of Laravel. It is an instance of Symfony\Component\HttpFoundation\Cookie. The cookie can be attached to the response using the withCookie() method. Create a response instance of Illuminate\Http\Response class to call the withCookie() …

Read More »

Laravel Request

Retrieving the Request URI The “path” method is used to retrieve the requested URI. The is method is used to retrieve the requested URI which matches the particular pattern specified in the argument of the method. To get the full URL, we can use the url method. Example Step 1 − Execute the below command to create …

Read More »

Laravel Controllers

In the MVC(Model View Controller) framework, the letter ‘C’ stands for Controller. It acts as moving the traffic back and forth between model and views. Creating a Controller Type the following command to create controller using the Artisan CLI (Command Line Interface). php artisan make:controller <controller-name> --plain This will create …

Read More »

Laravel Namespaces

Namespaces can be defined as a class of elements in which each element has a unique name to that associated class. It may be shared with elements in other classes. Declaration of namespace The use keyword allows the developers to shorten the namespace. use <namespace-name>; The default namespace used in Laravel is …

Read More »

Laravel Middleware

Middleware acts as a bridge between a request and a response. It is a type of filtering mechanism. Laravel includes a middleware that verifies whether the user of the application is authenticated or not. If the user is authenticated, it redirects to the home page otherwise, if not, it redirects …

Read More »

Laravel Routing

In Laravel, all requests are mapped with the help of routes. Basic routing routes the request to the associated controllers. Routing in Laravel includes the following categories − Basic RoutingRoute parametersNamed Routes Basic Routing All the application routes are registered within the app/routes.php file. This file tells Laravel for the URIs it …

Read More »