samedi 24 février 2018

Redirect to show page after creating an add

I have an app where users can create a pproperty add through the store route. If this is successful i want to use return redirect to follow the route that controls the show page. The route is /property/id

These are the store, and show controllers.

  public function store(Request $request, $id){
      $Advert = new PropertyAdvert();

      $Advert::create(
        [
          "photo"       => base64_encode(file_get_contents($request->photo->path())),
          "address"     => $request->address,
          "county"      => $request->county,
          "town"        => $request->town,
          "type"        => $request->type,
          "rent"        => $request->rent,
          "date"        => $request->date,
          "bedrooms"    => $request->bedrooms,
          "bathrooms"   => $request->bathrooms,
          "furnished"   => $request->furnished,
          "description" => $request->description
        ]
      );

    return redirect('/property/id');
    }

    public function show($id){
      $user = Auth::user();
    $Advert = PropertyAdvert::where('id', $id)->first();
    return view('pages/Advert/show', compact('Advert', 'user'));
  }

Just using /property/id doesn't seem to work, as it does in the routes when you type it in.

Routes Route::post('/createadvert', 'AdvertisementController@store');

Route::get('/property/{id}', 'AdvertisementController@show');



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire