Laravel和独特的slu ..

时间:2015-09-26 08:50:23

标签: php laravel-4 slug

我正在尝试生成一个获得独特的slu ,,就像MyBB一样,但它确实运作不好......

我正在使用https://github.com/cviebrock/eloquent-sluggable/tree/2.x插件Laravel 4.2

所以我明白了:

use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;

class ForumController extends \BaseController implements SluggableInterface {

    use SluggableTrait;

    protected $sluggable = [
        'build_from' => 'title',
        'save_to'    => 'slug',
    ];

在那个班级,我不知道如何生成slu ,, 它需要在这个函数中生成:

public function PostTopic($cid)
    {
        //Get all the data and store it inside Store Variable

        $data = Input::all();

        // Make's messages of faults
        $messages = array(
           'title.required'     => 'U moet een titel opgeven!',
           'titel.unique'       => 'De opgegeven titel bestaat al, gebruik een andere.',
           'message.required'   => 'u moet een bericht opgeven!',
           'spamprt'            => 'honeypot', //spam protection
           'time'               => 'required|honeytime:60'
        );

        $rules = array(
            'title' => 'required',
            'message' => 'required'
            );

        $validator = Validator::make($data, $rules, $messages);

        //process the storage
        if ($validator->fails())
        {
            return Redirect::back()->with('errors', $validator->errors())->withInput();
        }else{

            //store
            $thread                     = new Thread;
            $thread->cid                = $cid;
            $thread->title              = Input::get('title');
            $thread->message            = Input::get('message');
            $thread->prefix             = 0;
            $thread->uid                = Auth::id();
            $thread->username           = Auth::user()->username;
            $thread->date_posted        = Carbon\Carbon::now();
            $thread->save();
            Session::put('_token', sha1(microtime()));
            //redirect
            return Redirect::back()->with('message', 'Uw bericht is succesvol geplaatst!');
            }
    }
但是怎么样?我如何让slu to在URL中显示它们呢?

0 个答案:

没有答案