laravel 4.1存储URL参数,是否可能?

时间:2014-10-22 12:58:03

标签: php laravel-4 url-parameters

我仍然是一名学生,而且仍然是这些框架的新手

所以我的路线中有两个控制器:

Route::resource('homeworks', 'HomeworkController');
Route::resource('submithomeworks', 'SubmithomeworkController');

在views / Homework / show.blade.php中,我有:

href="{{ URL::action('submithomeworks.create', $homeworks->id) }}"

所以网址将来自

http://localhost:8000/homeworks/1 

http://localhost:8000/submithomeworks/create?1

那么有什么方法可以将$homework->id在这种情况下只存储1submithomeworks表吗?

我在SubmithomeworksController

上尝试了这个
public function store()
{
    $rules = array(
        'homework_id'       => 'required',
        'homework_body'     => 'required'

    );

    $submithomework = new Submithomework;
    $submithomework->homework_id        = Input::get('homework_id');
    $submithomework->homework_body      = Input::get('homework_body');
    $submithomework->student_id         = Auth::user()->id;
    $submithomework->save();

    Session::flash('message', 'Homework successfully added.');
    return Redirect::to('homeworks');

}

但是在视图中我该怎么做?它不会存储homework_id表示它仍为NULL

1 个答案:

答案 0 :(得分:0)

如果您需要访问路线参数,可以使用Route外观。例如:

Route::input('id');

您可以查看Laravel Docs