Laravel interview questions and answers 2017 — Laravel Interview Questions

  1. Hassles code reusability.
  2. Eloquent ORM with PHP active record implementation
  3. Built in command line tool “Artisan” for creating a code skeleton , database structure and build their migration
  1. Laravel is new framework and composer is not so strong in compare to npm (for node.js), ruby gems and python pip.
  2. Development in laravel is not so fast in compare to ruby on rails.
  3. Laravel is lightweight so it has less inbuilt support in compare to django and rails. But this problem can be solved by integrating third party tools, but for large and very custom websites it may be a tedious task
composer create-project laravel/laravel your-project-name version
  • php artisan help
  • php artisan tinker
  • php artisan make
  • php artisan –versian
  • php artisan make modal modal_name
  • php artisan make controller controller_name
  • Envoy
  • Passport
  • Scout
  • Socialite
Route::get('user/profile', function () { // })->name('profile');  You can specify route names for controller actions:  Route::get('user/profile', 'UserController@showProfile')->name('profile');  Once you have assigned a name to your routes, you may use the route's name when generating URLs or redirects via the global route function:  // Generating URLs... $url = route('profile'); // Generating Redirects... return redirect()->route('profile');
// creating Migration php artisan make:migration create_users_table
use Illuminate\Support\Facades\Cache; Route::get('/cache', function () { return Cache::get('key'); });
// Querying or finding records from products table where tag is 'new' $products= Product::where('tag','new'); // Inserting new record $product =new Product; $product->title="Iphone 7"; $product->price="$700"; $product->tag='iphone'; $product->save();
DB::connection()->enableQueryLog(); You can get array of the executed queries by using getQueryLog method: $queries = DB::getQueryLog();
//add an array of Routes to skip CSRF check private $exceptUrls = ['controller/route1', 'controller/route2']; //modify this function public function handle($request, Closure $next) { //add this condition foreach($this->exceptUrls as $route) { if ($request->is($route)) { return $next($request); } } return parent::handle($request, $next); }
trait Sharable { public function share($item) { return 'share this item'; } } You could then include this Trait within other classes like this: class Post { use Sharable; } class Comment { use Sharable; } 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 item' $comment = new Comment; echo $comment->share(''); // 'share this item'
composer create-project --prefer-dist laravel/lumen blog
Below is sample uses class User extends Eloquent{ protected $table="my_user_table"; }
  • One To Many
  • One To Many (Inverse)
  • Many To Many
  • Has Many Through
  • Polymorphic Relations
  • Many To Many Polymorphic Relations
  • Your production database needs to be synced as well.
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • Mbstring PHP Extension
  • Tokenizer PHP Extension
  • XML PHP Extension
  • max()
  • min()
  • avg()
  • sum()

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store