I
I
ilya173922019-08-22 12:12:33
Laravel
ilya17392, 2019-08-22 12:12:33

How, after creating an article using the store method, go directly to the page from its display?

There is a store method

public function store(AdRequest $request)
    {
       
        Ad ::create([

        'title' => $request->title,
        'description' => $request->description,
        'user_id' => Auth::user()->id,
        'author_name' => Auth::user()->username
        
    ]);
 
    }

HTML for it:
@if (count($ad) > 1)
        @foreach ($ad as $a)

        <div class="card-header mb-3">
            <h3><a href="{{ route('adShow', ['id'=>$a->id]) }}">{{ $a->title }}</a></h3>
            <p>{{ $a->description }}</p>
            <small>Author name: {{ $a->author_name }}</small><br/>
            <small>Created At {{ $a->created_at }}</small>
        </div>


        @endforeach

there is also a show method which works as it should
public function show($id)
    {
        $oneAd = Ad::find($id);

        
        return view('ad-content', [
            'oneAd' => $oneAd
        ]);
            
    }

and HTML for the show method
<div class="card-header mb-3">
            <h3>{{ $oneAd->title }}</h3>
            <p>{{ $oneAd->description }}</p>
            <small>Author name: {{ $oneAd->author_name }}</small><br/>
            <small>Created At {{ $oneAd->created_at }}</small>
        </div>

Route
Route::get('/{id}', '[email protected]')->name('adShow');

How to make it so that when creating an ad, immediately go to the page with the same post??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2019-08-22
@ilya17392

How to make it so that ... move

https://laravel.com/docs/5.8/redirects

O
organica, 2019-08-22
@organica

public function store(AdRequest $request)
    {
       
        Ad ::create([

        'title' => $request->title,
        'description' => $request->description,
        'user_id' => Auth::user()->id,
        'author_name' => Auth::user()->username
        
    ]);
 return redirect('/');
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question