mardi 29 septembre 2015

Laravel access classes without namespace in views

Usually, with laravel out of the box I am able to access the default "User" model without prefixing namespace routes, within any view, like so:

User::find(1);

However, if I create another model, for example - "Business", in order to access it in views I need to do the following:

App\Business::find(1);

Is there any way to "use" the classes globally in all views, so it works just like User class?

Thanks in advance.

Edit: It works if I do the following in a blade.php file, for example:

@extends('layouts.main')

@section('content')
    <?php
        use App\Business;
    ?>
    {{ Business::find(1)->name }}
@stop

But it seems like a not-so-clean way to do it. Or am I wrong and this is acceptable?

P.S - Using Laravel 5.1



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1FGR2zJ
via IFTTT

Aucun commentaire:

Enregistrer un commentaire