我想将person_id值从函数search()传递给函数view_application(),以使用此person_id将视图数据返回到详细信息页面。这里我的控制器代码是
<?php
namespace App\Http\Controllers;
use Faker\Provider\ar_JO\Person;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Application;
use App\Personal;
class CandidatesApplyController extends Controller
{
public function index(){
return view('admin.candidates-apply')
->with('application', Application::all());
}
public function search(Request $request)
{
if ($request->ajax())
{
$output="";
$application = DB::table('application')->where('person_id', 'LIKE', '%' .$request->search.'%')
->orWhere('name_khmer', 'LIKE', '%' .$request->search.'%')
->orWhere('name_latin', 'LIKE', '%' .$request->search.'%')
->get();
if ($application) {
foreach ($application as $key => $applications) {
$output .= '<tr>'.
'<td>'.$applications->person_id.'</td>'.
'<td>'.$applications->name_khmer.'</td>'.
'<td>'.$applications->name_latin.'</td>'.
'<td>'.$applications->app_sex.'</td>'.
'<td>'.$applications->app_dob.'</td>'.
'<td>'.$applications->app_nat.'</td>'.
'<td>'.$applications->app_pob.'</td>'.
'<td>'.$applications->app_current.'</td>'.
'<td>'.$applications->e_mail.'</td>' .
'<td>'.$applications->telephone.'</td>'.
'<td>'.$applications->app_no.'</td>'.
'<td>'.$applications->app_title.'</td>'.
'<td>'.$applications->created_at.'</td>'.
'<td>'."
<div class='btn btn-md btn-info' style='margin-left: 15px; padding: 10px 15px 0px 15px;'>
<a href='#' style='color: #fff;'><p>ពិនិត្យ</p></a>
</div>".'</td>'.
'<td>'."
<div class='btn btn-md btn-info' style='margin-left: 15px; padding: 10px 15px 0px 15px;'>
<a href='./candidate-application' target='_blank' style='color: #fff;'><p>ពិនិត្យ</p></a>
</div>".'</td>'.
'</tr>';
}
return response()->json($output);
}
}
return view('admin.candidates-apply', compact('application'));
}
public function view_application($id){
$app = DB::table('application')->wherePersonId($id)->get();
return view('admin.candidate-application', compact('app'));
}
}
,我的路线是
Route::get('/candidates-apply', 'CandidatesApplyController@search')->middleware('auth');
/* Candidate Application Detail View Route*/
Route::get('/candidate-application', 'CandidatesApplyController@view_application', function (){
return view('admin.candidate-application');
})->middleware('auth');
如何做到这一点。谢谢和问候,
答案 0 :(得分:0)
如果我理解你正在尝试做什么。
1解决方案:
修改您的路线:
/candidate-application/4
如果您的候选人ID为4,则您的操作链接应为exmaple <a href='/candidate-application/'.$applications->person_id></a>
,并且它会自动传递给您在函数中的id参数。
将此添加到搜索功能
中的链接Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect() in ....
2解决方案:
您可以提交带有ID的表单,并以与搜索相同的方式检索它。