Laravel Interview Questions

Trendy Laravel Interview Questions

Laravel interview Questions

Laravel makes it easy to protect your application from cross-site request forgery (CSRF) attacks. Cross-site request forgeries are a type of malicious exploit whereby unauthorized commands are performed on behalf of an authenticated user.
Laravel automatically generates a CSRF "token" for each active user session managed by the application. This token is used to verify that the authenticated user is the one actually making the requests to the application.
Traits are a mechanism that allows you to create reusable code in languages like PHP where multiple inheritances are not supported. A Trait is simply a group of methods that you want to include within another class. A Trait, like an abstract class, cannot be instantiated on its own
An example of a Trait could be: trait SharePost { public function share($item) { return 'share this post'; } } You could then include this Trait using 'use' within other classes like this: class Post { use SharePost; } class Comment { use SharePost; } Now if you were to create new objects out of these classes you would find that they both have the share() method available: $post = new Post; echo $post->share(''); // 'share this post' $comment = new Comment; echo $comment->share(''); // 'share this post'   For more see these links: https://medium.com/@kshitij206/traits-in-laravel-5db8beffbcc3 https://youtu.be/oj0FWrNsr-4  
Middleware provide a convenient mechanism for filtering HTTP requests entering your application. For example, Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application. Additional middleware can be written to perform a variety of tasks besides authentication. A CORS middleware might be responsible for adding the proper headers to all responses leaving your application. A logging middleware might log all incoming requests to your application. There are several middleware included in the Laravel framework, including middleware for authentication and CSRF protection. All of these middleware are located in the app/Http/Middleware directory.
  1. step1: in the terminal we create php artisan make: middleware middleware_name
  2. step2: a file will be created in the projectfolder/App/Http/Middleware/yourmiddle.php  folder
  3. step3: we have to register that globally .for that in projectfolder/App/Http/kernel.php we will include the path in clause
A function that calls itself is known as a recursive function. And, this technique is known as recursion. The recursion continues until some condition is met to prevent it. For example: void recurse() { ... .. ... recurse(); ... .. ... } int main() { ... .. ... recurse(); ... .. ... } Traits are a mechanism that allows you to create reusable code in languages like PHP where multiple inheritances are not supported. A Trait is simply a group of methods that you want to include within another class. Recursion repeatedly works until it fulfil the condition and on the hand in trait,we just include multiple function so that we can use whenever we need.trait helps to solve the problem multiple inheritance but recursion can not.
  • The session is a global variable that is used in the server to store the session data. When a new session creates the cookie with the session id is stored on the visitor's computer. The session variable can store more data than the cookie variable.
  • Session data are stored in a $_SESSION array and Cookie data are stored in a $_COOKIE array. Session values are removed automatically when the visitor closes the browser and cookie values are not removed automatically. Session and cookie both are used to store values or data.
  • cookie stores data in your browser and a session is stored on the server. Session destroys that when browser close and cookie delete when set time expires.
Laravel saves the session as a cookie that's why after closing the browser, info or data is not removed.
Basically, because Composer can't see the migration files you are creating, you are having to run the dump-autoload command which won't download anything new, but looks for all of the classes it needs to include again. It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php), and this is why your migration is working after you run that command.

Comments are closed.