Laravel face questions and answers

Laravel based Symfony is a free open source framework for PHP Web. It was created by Taylor Otwell, it allows developers to write expressive and elegant syntax. Laravel built-in support for user authentication and authorization, which is missing in some of the most popular PHP frameworks (such as CodeIgniter, CakePHP) in. Laravel by reading the following interview questions and answers, help your rise to the occasion in the interview process, but also as an evaluation or review and consolidate knowledge Laravel.

1. How to enable query logging in Laravel in?

Using the enableQueryLogmethod enabled in Laravel query log in -

DB::connection()->enableQueryLog(); 

// 可以使用getQueryLog方法获取已执行查询的数组:
$queries = DB::getQueryLog();

2. What are the advantages and disadvantages Laravel framework?

An advantage of using frame Laravel

  • Laravel framework has a built-blade lightweight template engine, can speed up the compilation task and easily create layouts with dynamic content.
  • Improve code reusability.
  • Eloquent ORM and PHP activities to achieve record.
  • Built-in command line tool "Artisan", the code used to create the framework, database structure and build its migration.

The disadvantage of using the frame laravel

  • Development process requires that you use the standard, and there should be an understanding of programming
  • Laravel is the new framework,, ruby ​​gems and python pip compared with npm (for node.js), Laravel is not so strong.
  • Compared with ruby ​​on rails, laravel development speed is not fast.
  • Laravel is lightweight, compared with django and rails, it has fewer built-in support. But this problem can be solved by integrating third-party tools, but for large and very customizable website, this can be a tedious task.

What 3. Laravel contracts (Contracts) that?

Laravel contracts (Contracts) is simply a set of interfaces that define the core services of the Laravel framework.

4. Laravel Eloquent available Relationship What?

The following is a Laravel Eloquent ORM support the relationship type.

  • One to One
  • Many
  • To-many (inverse)
  • Many to many
  • How through (Has Many Through)
  • Multi-state relations
  • Polymorphic many relationship

Dependency injection 5. Laravel what it is?

In software engineering, dependency injection is a technique in which a dependency object provides another object. Dependency is an object that can be used (service). Dependency injection is transmitted to the dependent objects that will use it (the client). The customer service becomes part of your state. The service delivery to the client, rather than allowing clients to build or lookup service is the basic requirement mode.

Reference: https://en.wikipedia.org/wiki/Dependency_injection

Dependency may be injected through the Constructor, setter and property injection.

What 6. laravel of events?

Event is an action or event may be a program or code recognition processing program. Laravel event provides a simple viewer realize, for a variety of events and listeners subscribe to the application / operation. All event classes are usually stored in the app / Events directory and its listeners are stored in the app / Listener application.

7. How to turn off CSRF protection Laravel particular route?

To turn off CSRF protection Laravel, make the file: App / Http / Middleware / VerifyCsrfToken.php  Add the following code -

//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);
}

8. PHP what the Composer is? 

Composer is a tool for managing PHP dependent. It is used to declare the project depends libraries, and management (install / update) them. Laravel use Composer to manage its dependencies.

9. Why do you need to migrate?

Migration is necessary because:

  • Without migration, database consistency when shared applications is almost impossible, especially as more and more people collaborate on Web applications.
  • Production databases need to be synchronized.

10. Please explain what Laravel service containers are?

Laravel one of the most powerful features is its service container. It is a powerful tool for solving class dependencies and Laravel perform dependency injection.
Dependency injection is a peculiar phrase, essentially by means dependent class constructor "injection" type, or in some cases, "injection" method.

11. How can I check request is ajax request?

In Laravel may be used $request-> ajax()a method to check whether the request ajax.

Example:

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

12. Laravel's what Traits that?

PHP Traits just want a set of methods in another class contains. Trait like an abstract class, can not themselves be instantiated. By enabling developers to freely reuse methodology in several independent classes living in different class hierarchy, create a Trait PHP in order to reduce the single inheritance restrictions.

Here is an example of Traits.

trait Sharable {

  public function share($item)
  {
    return 'share this item';
  }

}

PHP

Then, this Trait may be included in other classes, as follows:

class Post {

  use Sharable;

}

class Comment {

  use Sharable;

}

PHP

Now, if you want to create a new object of these classes, you will find that they have share()methods available:

$post = new Post;
echo $post->share(''); // 'share this item' 

$comment = new Comment;
echo $comment->share(''); // 'share this item'\n

13. What is the ISP / provider?

ISP is all laravel application guide central location. Your application and all Laravel core services are guided by the service provider.
All service providers extend the IlluminateSupportServiceProviderclass. Most service providers and a guiding method comprising registers. In the registerprocess, things should only be bound to a service container. You should never attempt registerto register any event listener method, routing, or any other function.

14. What is Laravel?


Laravel is based on free open source "PHP frameworks" MVC design pattern. It was created by Taylor Otwell. Laravel provides expressive and elegant syntax help easily create great Web applications quickly.

 

15. Please explain verify laravel in?

In programming, verification is a convenient way to ensure that data is always in the database before entering the clean and the expected format. Laravel provides several different ways to validate incoming data applications. By default, the base controller class Laravel use ValidatesRequestscharacteristics, it provides a convenient way to verify all incoming HTTP requests from the client. Laravel verification data may also be created by the form request.

16. Please list some of the default package Laravel 5.6 provided?


Here are some of the official list of the default package / Laravel 5.6 provides:

Cashier
Envoy
Passport
Scout
Socialite
Horizon

17. What is a database migration? How to create a migration by artisan?

Like the version control database migration, like the development team to easily edit and share application database schema. Migration is usually paired with a builder Laravel framework to easily build database application architecture.

Use the following command to create the migration of data through artisan.

// creating Migration
$ php artisan make:migration create_users_table

18. Laravel what route is the reverse?

Laravel reverse route to generate URL according to the route statement. The reverse route applications more flexible. It defines the relationship between links and Laravel routes. When you create a link using the name of an existing path, Laravel will automatically create the appropriate Uri. Here is an example of reverse routing.

// route declaration
Route::get('login', 'users@login');

PHP

Using the reverse route, we can create a link, and pass any parameters defined. If not provided, the optional parameters from the generated link deleted.

{{ HTML::link_to_action('users@login') }}

PHP

It automatically generates a similar view  http://xyz.com/login  URL.

19. The method of polymerization are some builders offered Laravel query?


Some polymerization processes Laravel query builder provides as follows:

count()
max()
min()
avg()
sum()

20. How to install laravel by composer?

You can use the composer Laravel installation by running the following command.

$ composer create-project laravel/laravel your-project-name version

 

21. Laravel what's eloquent that?

 

Laravel the Eloquent ORM is a simple Active Record implementation of the database for processing. Laravel offers many different ways to interact with the database, Eloquent most striking. Each database table has a corresponding "model" for interacting with the table. Model may be used to query the data tables, and inserting a new record in the table.

Here is an example of usage Eloquent query and insert a new record in the Database.

// Querying or finding records from products table where tag is 'new'\n$products= Product::where('tag','new');
// Inserting new record 
 $product =new Product;
 $product->title="Iphone 7";
 $product->price="$700";
 $product->tag='iphone';
 $product->save();

22. Please list some of the features of laravel 5.0?

Some features are as follows laravel 5.0 -

  • Built-in CSRF (cross-site request forgery) protection.
  • Built-in pagination
  • Reverse route
  • Query Builder
  • Route cache
  • Database Migration
  • IOC (Inversion of Control) service container or containers.

 

23. What is PHP artisan? Please list some of the artisan's command?

PHP artisan is a command-line interface / tool that comes with Laravel. It provides a number of useful commands, can help you easily build applications. Here are some artisan list of commands: -

  • php artisan list
  • php artisan help
  • php artisan tinker
  • php artisan make
  • php artisan –versian
  • php artisan make model model_name
  • php artisan make controller controller_name

24. How to use custom tables in Laravel Modal in?

Eloquent protected by the cover $tableto use the custom table Laravel attributes.

Example:

class User extends Eloquent{
 protected $table="my_user_table";

}

PHP

 

Whether 25. Laravel supports caching?

Of course support. Laravel cache backend popular support, such as: Memcached and Redis.
By default, configured to use the file cache Laravel driver, the driver serialized object storage cache in file system. For large projects, we recommend using Memcached or Redis.

26. Lumen What is that?

 

Lumen is a PHP micro framework is based on Laravel top assembly. It was created by Taylor Otwell. It is based on Laravel build the perfect choice of micro and fast service REST API's. It is one of the fastest micro framework.
Lumen can be installed by running the following command using the composer -

$ composer create-project --prefer-dist laravel/lumen blog

27. Please explain Laravel in the bundle?

In the Laravel, bundle also called bundle. Laravel bundle is the main way to expand functionality. Package may be a good way to deal with the date like Carbon, or the entire BDD testing framework like Behat. In Laravel, or you can create a custom bundle.

28. install Laravel framework server system environments What are the requirements?

To install Laravel, make sure that your server meets the following requirements:

  • PHP> = 7.1.3
  • OpenSSL PHP extension
  • PDO PHP extension
  • Mbstring PHP extension
  • Tokenizer PHP extension
  • XML PHP extension
  • Ctype PHP extension
  • JSON PHP extension

What named route 29. Laravel framework is?

Named routing is another amazing feature Laravel framework. Naming routing allows more convenient reference when generating the routing or redirection Urls. It can be nameused to specify the naming method for routing links to route definition:

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

PHP

You can specify the route name for the controller operation:

Route::get('user/profile', 'UserController@showProfile')->name('profile');

PHP

After specifying a path name, path name may be used when generating the URL, or by the global redirection path function:

// Generating URLs...
$url = route('profile');
// Generating Redirects...
return redirect()->route('profile');

30. Please explain what Laravel of Facades that?

Laravel Facades provide static-like application services available container class interface. Laravel self loading many Facades, you can see almost all the features of Laravel. Laravel appearance acts as a service container in the bottom of the class' static proxy "to provide concise, expressive syntax, while maintaining testability and more flexibility than the traditional static class method. Facades Laravel are all in IlluminateSupportFacadesthe definition of namespace. So you can easily access Facades:

use Illuminate\Support\Facades\Cache;

Route::get('/cache', function () {
    return Cache::get('key');
});

PHP

 

31. Laravel what middleware (Middleware) that?
 

As the name suggests, Middleware acts as an intermediary between requests and responses. It is a filtering mechanism. For example, Laravel includes a middleware user to verify whether the application authenticated. If the user is authenticated, he will be redirected to the home page, otherwise, he will be redirected to the login page.

Laravel There are two types of middleware.

  • Global Middleware: will run on each HTTP request application.
  • Routing intermediate: will be assigned to a particular route.
Published 72 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_39399966/article/details/104344997