简体   繁体   中英

PHP - redirect to the page of the newly added item?

How would I redirect to the page of the newly added item?

For example, I have 5 page list of items. After I successfully added a new item, I want it to redirect to the page where it should be located.

Is it possible? How?

<?php

class PostController extends BaseController
{

    ...

    public function store()
    {
        $input = Input::all();

        // do validation, etc...

        $post = Post::create($input);

        return Redirect::to("/posts/{$post->id}/detail");
    }

    ...

}

Post is Eloquent model here. create method stores data in database and return newly created object, which is assigned back to $post variable. All it's properties are accessible from this point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM