Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 我可以在刀片模板中使用外观吗?_Laravel_Laravel Blade - Fatal编程技术网

Laravel 我可以在刀片模板中使用外观吗?

Laravel 我可以在刀片模板中使用外观吗?,laravel,laravel-blade,Laravel,Laravel Blade,我已经安装了这个软件包。 我已经完成了指南中的所有步骤 我的别名是 'aliases' => [ 'App' => Illuminate\Support\Facades\App::class, 'Artisan' => Illuminate\Support\Facades\Artisan::class, 'Auth' => Illuminate\Support\Facades\Auth::class, 'Blade' => Illu

我已经安装了这个软件包。 我已经完成了指南中的所有步骤

我的
别名是

'aliases' => [

    'App' => Illuminate\Support\Facades\App::class,
    'Artisan' => Illuminate\Support\Facades\Artisan::class,
    'Auth' => Illuminate\Support\Facades\Auth::class,
    'Blade' => Illuminate\Support\Facades\Blade::class,
    'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
    'Bus' => Illuminate\Support\Facades\Bus::class,
    'Cache' => Illuminate\Support\Facades\Cache::class,
    'Config' => Illuminate\Support\Facades\Config::class,
    'Cookie' => Illuminate\Support\Facades\Cookie::class,
    'Crypt' => Illuminate\Support\Facades\Crypt::class,
    'DB' => Illuminate\Support\Facades\DB::class,
    'Eloquent' => Illuminate\Database\Eloquent\Model::class,
    'Event' => Illuminate\Support\Facades\Event::class,
    'File' => Illuminate\Support\Facades\File::class,
    'Gate' => Illuminate\Support\Facades\Gate::class,
    'Hash' => Illuminate\Support\Facades\Hash::class,
    'Lang' => Illuminate\Support\Facades\Lang::class,
    'Log' => Illuminate\Support\Facades\Log::class,
    'Mail' => Illuminate\Support\Facades\Mail::class,
    'Notification' => Illuminate\Support\Facades\Notification::class,
    'Password' => Illuminate\Support\Facades\Password::class,
    'Queue' => Illuminate\Support\Facades\Queue::class,
    'Redirect' => Illuminate\Support\Facades\Redirect::class,
    'Redis' => Illuminate\Support\Facades\Redis::class,
    'Request' => Illuminate\Support\Facades\Request::class,
    'Response' => Illuminate\Support\Facades\Response::class,
    'Route' => Illuminate\Support\Facades\Route::class,
    'Schema' => Illuminate\Support\Facades\Schema::class,
    'Session' => Illuminate\Support\Facades\Session::class,
    'Storage' => Illuminate\Support\Facades\Storage::class,
    'URL' => Illuminate\Support\Facades\URL::class,
    'Validator' => Illuminate\Support\Facades\Validator::class,
    'View' => Illuminate\Support\Facades\View::class,
    'Transliterate' => ElForastero\Transliterate\Facade::class,

],
我的
提供者

'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    Illuminate\Bus\BusServiceProvider::class,
    Illuminate\Cache\CacheServiceProvider::class,
    Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class,
    Illuminate\Cookie\CookieServiceProvider::class,
    Illuminate\Database\DatabaseServiceProvider::class,
    Illuminate\Encryption\EncryptionServiceProvider::class,
    Illuminate\Filesystem\FilesystemServiceProvider::class,
    Illuminate\Foundation\Providers\FoundationServiceProvider::class,
    Illuminate\Hashing\HashServiceProvider::class,
    Illuminate\Mail\MailServiceProvider::class,
    Illuminate\Notifications\NotificationServiceProvider::class,
    Illuminate\Pagination\PaginationServiceProvider::class,
    Illuminate\Pipeline\PipelineServiceProvider::class,
    Illuminate\Queue\QueueServiceProvider::class,
    Illuminate\Redis\RedisServiceProvider::class,
    Illuminate\Auth\Passwords\PasswordResetServiceProvider::class,
    Illuminate\Session\SessionServiceProvider::class,
    Illuminate\Translation\TranslationServiceProvider::class,
    Illuminate\Validation\ValidationServiceProvider::class,
    Illuminate\View\ViewServiceProvider::class,

    /*
     * Package Service Providers...
     */
    ElForastero\Transliterate\ServiceProvider::class,

    /*
     * Application Service Providers...
     */
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    // App\Providers\BroadcastServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,

],
我想在我的刀片模板中写下如下内容:

     @foreach($services as $service)
            <div class="content" data-content="{{ Transliterate::slugify($service->tag) }}">
                <div class="list-previews-cases -closed">
                    <div class="cases">
                        @foreach($service->cases as $case)
                        <div class="case">
                            <img
                                src="{{ $case->preview_img }}"
                                class="img"
                                alt="">
                            <div class="title">{{ $case->title }}</div>
                            <div class="description">{{ $case->description }}</div>
                            <a href="/" class="link -blue">#{{ $service->tag }}</a>
                        </div>
                        @endforeach
                    </div>
                    @if($service->cases->count() > 1)
                    <span class="spoiler">More...</span>
                    @endif
                </div>
            </div>
            @endforeach
@foreach($services as$service)
@foreach($service->cases as$case)
预览_img}”
class=“img”
alt=”“>
{{$case->title}
{{$case->description}
@endforeach
@如果($service->cases->count()>1)
更多
@恩迪夫
@endforeach
但结果我看到了以下几点:


<什么是错误的?我可以在我的刀片模板中使用外观吗?

< P>根据MVC,你不应该在你的视图文件中使用任何复杂的逻辑。考虑把它移动到你的控制器上:
use ElForastero\Transliterate\Facade as Transliterate;

...
$slug = Transliterate::slugify($service->tag);
return view('your.view', ['slug' => $slug, ...]);
如果仍然希望在视图文件中访问facade,可以通过指定其类的完整路径来实现,如so
ElForastero\translation\facade::slugify(service->tag)

如果您希望在许多地方多次调用此代码,也可以将其包装成一个helper函数。只需在
Helpers/functions.php
中创建一个新函数,如下所示:

use ElForastero\Transliterate\Facade as Transliterate;

...
function slugify($tag) {
    return Transliterate::slugify($tag);
}

然后在您的视图中这样调用它:
{{{slagify($service->tag)}

是的,您可以在blade中使用Facade,它在控制器中工作吗?
translitate::slagify($service->tag)
如果您使用
elforastro\translitate\Facade::slagify($service->tag)
而不是
translitate::slagify($service->->标签)
它可以工作吗?谢谢。它可以从盒子中工作。不要忘记使用根命名空间(由命名空间中的第一个
\
表示)
\translitate::slagify($service->tag)
\elforastro\translitate\Facade::slagify($service->tag)
。您是否记得使用
php artisan cache:clear
composer dump
清除任何缓存的配置文件以确保安全?