Question: How to make a helper file in laravel?
- Please create a app/helpers.php file in app folder.
- Add Following in in autoload variable.
"files": [ "app/helpers.php" ]
- Now update your composer.json
composer update
Question: How to use mail() in laravel?
Mail::send('emails.reminder', ['user' => $user], function ($m) use ($user) { $m->from('from@example.com', 'Send Name'); $m->to('receiver@example.com', 'Receiver Name')->subject('Your Reminder!'); });
Question: What is a REPL?
REPL is a type of interactive shell that takes in single user inputs, process them, and returns the result to the client. The full form of REPL is Read—Eval—Print—Loop
Question: How to use update query in Laravel?
Use Update function. for example
Blog::where(['id' => 10023])->update([ 'title' => 'Interview Questions', 'content’ => 'Web Technology exerts notes' ]);
Question: How to use multiple OR condition in Laravel Query?
Blog::where(['id' => 10023])->orWhere(['username’ => 'username12'])->update(['title' => 'Interview Questions',]);
Question: What are different type of where Clauses in Laravel?
- where()
- orWhere()
- whereBetween()
- orWhereBetween()
- whereNotBetween()
- orWhereNotBetween()
- wherein()
- whereNotIn()
- orWhereIn()
- orWhereNotIn()
- whereNull()
- whereNotNull()
- orWhereNull()
- orWhereNotNull()
- whereDate()
- whereMonth()
- whereDay()
- whereYear()
- whereTime()
- whereColumn()
- orWhereColumn()
- whereExists()
Question: What is updateOrInsert method? Give example?
updateOrInsert() method is used to update an existing record in the database if matching the condition or create if no matching record exists.
Blog::updateOrInsert([ 'title' => 'Interview Questions', ]);
Question: How to check table is exists or not in our database using Laravel?
if(Schema::hasTable('users')) { echo "Table Exists"; } else { echo "Table does not exists" }
Question: How to check column is exists or not in a table using Laravel?
if(Schema::hasColumn('users', 'title')) ; //check whether admin table has username column { echo "Column Exists in table"; }else{ echo "Column does not Exists in table"; }
Question: What are the difference between insert() and insertGetId() in laravel?
Inserts(): This method is used for insert records into the database table.
insertGetId(): This method is used for insert records into the database table and return the autoincrement-id.
Question: What is lumen?
Lumen is a PHP framework which is a faster, smaller and leaner version of a full web application framework.
Question: What is the full form of ORM in Laravel?
Object Relational Mapping.
Question: How to get current route name and method name?
request()->route()->getName(); //Return route name request()->route()->getActionMethod();//Return method name
Question: How to check Ajax request in Laravel?
You can use the following syntax to check ajax request in laravel.
if ($request->ajax()) { echo "This is ajax requrest"; }
Question: What do you mean by bundles? In Laravel, bundles are referred to as packages.
These packages are used to increase the functionality of Laravel.
A package can have views, configuration, migrations, routes, and tasks.
Question: Name databases supported by Laravel.
- PostgreSQL
- SQL Server
- SQLite
- MySQL