By OnlineInterviewQuestions com Php laravel Interview Questions What is Laravel?

Q20. What are traits in Laravel?

Download 39.11 Kb.
View original pdf
Size39.11 Kb.
1   2   3   4   5   6   7   8   9

What are traits in Laravel?
PHP Traits are simply a group of methods that you want include within another class. A Trait, like an abstract class cannot be instantiated by itself.Trait are created to reduce the limitations of single inheritance in PHP by

enabling a developer to reuse sets of methods freely in several independent classes living indifferent class hierarchies.
Here is an example of trait.
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'
Does Laravel support caching?
Yes, Laravel supports popular caching backends like Memcached and Redis.
By default, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the file system.For large projects, it is recommended to use Memcached or Redis.
Explain Laravel’s Middleware?
As the name suggests, Middleware acts as a middleman between request and response. It is a type of filtering mechanism. For example, Laravel includes a middleware that verifies whether the user of the application is

authenticated or not. If the user is authenticated, he will be redirected to the homepage otherwise, he will be redirected to the login page.
There are two types of Middleware in Laravel.
Global Middleware: will run on every HTTP request of the application.

Download 39.11 Kb.

Share with your friends:
1   2   3   4   5   6   7   8   9

The database is protected by copyright © 2022
send message

    Main page