dongyi1748 2014-10-22 12:58
浏览 33

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

I'm still a student and still new with these frameworks

so I have two controllers in my routes:

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

in views/Homework/show.blade.php, I have:

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

so the URL will go from

http://localhost:8000/homeworks/1 

to

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

so is there a way I can just store $homework->id which is just 1 in this situation to the submithomeworks table?

I tried this on the 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');

}

but what do I do after that in the view? it won't store the homework_id says its still NULL

  • 写回答

1条回答 默认 最新

  • dqbh8054 2014-10-22 13:09
    关注

    If you need to access a route parameter you can use the Route facade. For example:

    Route::input('id');
    

    You can check the Laravel Docs.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动