Laravel在同一视图上的几个更新

时间:2018-04-17 21:14:57

标签: laravel-5 routes

在设置过程中,我想:

  1. 选择应用程序的lang(1个或多个)...
  2. 更新数据库
  3. 选择默认语言
  4. 再次更新数据库......
  5. 为此,我创建了3条路线。

    Route::get('/home/setup', 'BackOffice\FirstconnectionController@initLang');
    Route::patch('/home/setup', 'BackOffice\FirstconnectionController@initLangUpdate')->name('setup.setLang');
    Route::patch('/home/setup', 'BackOffice\FirstconnectionController@setDefaultLang')->name('setup.setDefaultLang');
    
    • 第一个是我发表雄辩请求的主页
    • 第二条路线显示语言列表
    • 第三条路线显示已发布的语言列表......

    以下是我的观点:

    @if ($message = Session::get('success'))
        <div class="alert alert-success">
            <p>{{ $message }}</p>
        </div>
    @endif
    {{-- IF NO LANGS ARE PUBLISHED I CAN CHOOSE HERE --}}
    @if ($langsCount == 0)
        {!!  Form::model($langs, [
                'method' => 'PATCH',
                'route' => 'setup.setLang'
            ])
        !!}
        @foreach($langs as $lang)
            <div class="form-group">
                {{--<label class="col-md-4">  {{ $lang->langname }} </label>--}}
                {{--<input id="{{ $lang->langisocode }}" type="checkbox">--}}
    
                {!! Form::label($lang->langname,  $lang->langname ) !!}
                {!! Form::checkbox( 'lang[]', $lang->id ) !!}
            </div>
        @endforeach
        <div class="col-xs-12 col-sm-12 col-md-12 text-center">
            <button type="submit" class="btn btn-primary">Valider</button>
        </div>
        {!! Form::close() !!}
    
    {{-- NOW I SELECT DEFAULT LANGUAGE... --}}
    @else
        {!!  Form::model($langs, [
                'method' => 'PATCH',
                'route' => 'setup.setDefaultLang'
            ])
        !!}
    
        @foreach($pubLangs as $pubLang)
            {!! Form::label($pubLang->langname,  $pubLang->langname ) !!}
            {!! Form::radio( 'lang', $pubLang->id ) !!}
            <br>
        @endforeach
        <div class="col-xs-12 col-sm-12 col-md-12 text-center">
            <button type="submit" class="btn btn-primary">Valider</button>
        </div>
    
        {!! Form::close() !!}
    @endif
    

    这是我的控制器:

    // I display the info here
    public function initLang()
    {
    
        $langs = Lang::onlyTrashed()->get();
        $langsCount = Lang::count();
        $pubLangs = Lang::all();
    
        return view('admin.firstConnection', compact('langs', 'langsCount', 'pubLangs'));
    }
    
    public function initLangUpdate(Request $request) {
        $request = $request->input('lang');
        foreach ($request as $entry) {
            Lang::withTrashed()->find($entry)->restore();
        }
        return redirect('admin/home/setup')->with('success', 'OK');
    }
    
    public function setDefaultLang(Request $request) {
        $request = $request->input('lang');
        return $request;
    }
    

    我将在...之后更新setDefaultLang 我有这个错误消息: 路线[setup.setLang]未定义

0 个答案:

没有答案