Laravel 5 interview questions

Laravel 5 interview questions

Laravel is one of the most popular frameworks on Github. On Github, Laravel has 54,843+ stars which is growing day by day. Here you can 100+ Laravel interview questions that are taken from various open-source places like quora, Github, and StackOverflow

Download Laravel 5 interview questions PDF

Below are the list of Best Laravel 5 interview questions and Answers

Homebrew is an open-source software package management system for macOS and Linux. It helps Linux and macOS users for the installation of software in a simple manner. Homebrew is written in Ruby programming language and free to download.

You can use \Redirect::to('/new-url', 301); for 301 redirects.

example :

Route::get('old-url', function(){ 
    return Redirect::to('/bar', 301); 
});

Named routes allow the convenient generation of URLs or redirects for specific routes. You may define a name for a path by chaining the name process onto the path definition.

Example

Route::get('user/registration', function () {
    //
})->name('registration');

To list all registered routes in Laravel application you can use php artisan route:list command or also use Route::getRoutes(); method it will return a RouteCollection.

You can use url()->current(); method to get the current URL in Laravel Framework. This method returns only the URL without its parameter.If complete URLG with parameter is required then use url()->full();

Controller in Laravel is a class in which is responsible for controlling application execution flow. It sits between Model and view. Most of the business logic are written in the controller. In Laravel controllers are kept in the app/Http/Controllers directory.

Example Controller In Laravel

<?php

namespace App\Http\Controllers;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
       
    }

	public function index(Request $request){
		
				
	}
}

In Laravel, we can use $request->ajax() method to check request is ajax or not.

Example:

      public function saveData(Request $request)
        {
            if($request->ajax()){
                return "Request is of Ajax Type";
            }
            return "Request is of Http type";
        }

Macros provide a way to add functionality to the classes wherein you do not have that function. It can help you to create a small reusable component that'll be possible to use it everywhere on your application.