DEV Community

Robin  Dev
Robin Dev

Posted on • Originally published at larachamp.com on

Laravel Interview Questions For Beginners

In this article, we going to learn about Laravel interview questions so that you can have a clear vision of what you can be asked for. So, while covering these questions.

This is only for beginners if you want to look forward maybe you will find something new in this article. Let’s start learning and reading the questions.

What are the available route methods in Laravel

Routes help us to land on any HTTP verb and also help us to communicate with any kind of controller or model. In Laravel, we can find common routes in routes/web.php file

We have 6+ methods to put any kind of request further. Sometimes we need to define routes that respond to multiple HTTP verbs then we can use match method.

Route::get($uri, $callback);

Route::post($uri, $callback);

Route::put($uri, $callback);

Route::patch($uri, $callback);

Route::delete($uri, $callback);

Route::options($uri, $callback);

How to print route lists using Command?

We can use route:list Artisan command to print the list of routes.

What is the CSRF Token In Laravel

CSRF token actually works as a bodyguard to our website forms so, that anybody cannot hurt it. CSRF token is automatically generated by Laravel by itself for each application user. Whenever you do put a request with your form except getting method it gets regenerated with the session.

CSRF token is stored in the user session.

What are the **Regular Expression Constraints in Laravel?

You can use where() method on a route instance in which you can pass the name of the parameter and regular expression also. Which defined how parameters should be constrained. For example, you are passing a route with a user modal and you have a parameter with a user id so you can specify that the id should be a number.

Route::get('/user/{id}', function ($id) {
    //
})->where('id', '[0-9]+');

Enter fullscreen mode Exit fullscreen mode

How to check whether a user is authenticated or not in Laravel?

So, you have two options here to check whether a user is authenticated or not.

First, if you are into any php file you can use like:

if(Auth::check()){
//code
}

Enter fullscreen mode Exit fullscreen mode

And if you are adding any condition in the blade file then you can use like this:

@auth()
@endauth 

Enter fullscreen mode Exit fullscreen mode

What are the migrations in Laravel?

In simple, Migrations are used to create database tables in a very convenient way. Sometimes when you are working with a team, you do add some columns in a table and do push the code from your side. Then there sometimes this problem happens that you have to share the table with your team member but here database schema helps to do this all just by putting some line of code.

In short, migrations are really god-gifted concept to build tables in DB.

How we can generate the migrations

To generate the migration you have to use the command php artisan make:migration create_desired_table.

Full Form of ORM In Laravel?

object-relational mapper

How to generate Model Class in Laravel?

You can find Models in app/models the directory. The model extends Illuminate\Database\Eloquent\Model class. We can use the make: model artisan command to generate a modal class.

php artisan make:model Clients

Enter fullscreen mode Exit fullscreen mode

What is a One-To-Many Relationship?

We use the One-To-Many relationship when we want to get access to multiple models that own by a single modal.

For example, We have a user and this user has multiple comments on a post. So, now we have the user id and we have user_id it in the comments table. Then we just need to use a one-to-many relationship so that we can get the all comments written by this user.

These are just basic questions for beginners and not more of theortical but also for understanding the main points in just a simple way. I hope this will help you somewhere. Thanks

I will recommend you to read this article also. PHP interview questions for beginners

The post Laravel Interview Questions For Beginners first appeared on larachamp.com.

The post Laravel Interview Questions For Beginners appeared first on larachamp.com.

Top comments (0)