mardi 17 avril 2018

Several updates on the same view Laravel

In a setup process I want to:

  1. select langs of the application (1 or more) ...
  2. Update the DB
  3. Select the default language
  4. Update again the DB...

For this i created 3 routes.

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');

  • The first is the home page where i make eloquent requests
  • The second route display the list of languages
  • The third route displays the list of languages which are published ...

Here is my view :

@if ($message = Session::get('success'))
    <div class="alert alert-success">
        <p></p>
    </div>
@endif

@if ($langsCount == 0)
    {!!  Form::model($langs, [
            'method' => 'PATCH',
            'route' => 'setup.setLang'
        ])
    !!}
    @foreach($langs as $lang)
        <div class="form-group">
             </label>--}}
            " 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() !!}


@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

Here is my controller :

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

I will update the setDefaultLang after ... I have this error message : Route [setup.setLang] not defined



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire