在控制器Laravel中调用模型函数时如何将变量传递给模型?

时间:2019-07-27 12:24:45

标签: php laravel

<?php

namespace App\Http\Controllers\userController;

use App\Assign_reviewer;
use  App\paper_reply;
use App\submit_myreviews;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class mainreview extends Controller
{
    public function index($id)
    {
        $reviewers = Assign_reviewer::where('paper_id','=',$id)->with('get_user')->get();

        $Assign_reviewer = Assign_reviewer::where('paper_id','=',$id)->with('get_user')->get();

        $submit_myreviews = array();
        $paper_replys = array(); 

        foreach ($reviewers as $reviewer){
            $submit_myreview = $reviewer->get_submit_reviewers($reviewer['paper_id'],$reviewer['user_id'])->last();
            $paper_reply = $reviewer->get_paper_reply($reviewer['paper_id'],$reviewer['user_id'])->last();

            array_push($submit_myreviews, $submit_myreview);
            array_push($paper_replys, $paper_reply);
        }

        // dd($reviewers);
        $submit_myreviews_count = count($submit_myreviews);

        return view('user.mainreview.index',compact('id','reviewers','submit_myreviews_count','submit_myreviews'));
    }
}

1 个答案:

答案 0 :(得分:0)

仅在web.php中的路由中,您可以传递任何参数

Route::get('/uri/{parameter}','ControllerName@controllerMethod');

您可以写

Route::get('/uri/{id}','mainreview@index');