将数据从视图传递到Laravel中的控制器

问题描述 投票:0回答:1

我知道通过URL传递记录ID通常不是一个好主意,但我想知道如何避免这种情况:

我的目标是在用户仪表板上列出作业状态,并允许用户调整状态。

我创建我的视图并使用会话将变量传递给它:

userController.php

public function getdashboard()
    {
       //reading the user information
    $arrPageData['user'] = Sentry::getUser();
       //reading the job interviews
    $arrPageData['jobInterviews'] = JobInterview::readCurrentInterviews($this->userID);

    return View::make('clients.dashboard', $arrPageData);
    }

这部分效果很好,我在路线中不使用记录ID。我遍历仪表板视图中的jobInterviews。根据数据库表中列出的状态,我给用户选项

查看文件:dashboard.blade.php(摘要)

@foreach ($jobInterviews as $interviews)
    @if ($interviews->j == $job->id)
        <tbody>
        <tr>
        <td>
        {{$interviews->contact_name}}
        @if ($interviews->status == 'interview request accepted')

    <a href="#"  class="btn btn-danger btn-small" data-toggle="modal" data-target=".mymodal{{ $interviews->interview_id }}">Hire</a>
       @elseif ($interviews->status == 'hired')
        <button id="complete" class="btn btn-info btn-small">Mark Project Complete</button>
        @endif
        </td>
        <td>{{$interviews->status}} </td>
        </tr>
        </tbody>
         ...

我遇到的问题是要完成作业状态更改,我正在调用方法并传递记录ID:

仍在dashboard.blade.php中

<form action="../jobs/offer/{{$interviews->interview_id}}" method="post">

然后将其路由到:

Route::post('/jobs/offer/{id}','JobController@jobOffer');

一切都按我的意愿进行,但从安全角度来看,我认为我做的不正确。从迭代过的数组中获取数据时,除了在路由中使用记录ID之外,还有没有更好的方法来调用jobOffer方法并更改状态?

谢谢您的帮助。

php laravel laravel-4
1个回答
2
投票

您可以尝试以下方法:

{{ Form::open(array('action' => array('JobController@jobOffer', $interviews->interview_id))) }}
    <!-- Rest of the form fields -->
{{ Form::close() }}

这样,您无需手动添加csrf/_method输入,默认情况下,METHODPOST,因此您可以忽略它。

© www.soinside.com 2019 - 2024. All rights reserved.