我在数据库教室和状态中有两个表。课堂字段为id
,subject
,class_code
,user_id
。我为每个班级建立了一个链接。现在我想在每个班级的班级视图页面中显示数据。如果我的班级链接class?class_id=47
,则其必须仅显示class?class_id=47
数据,如果class?class_id=55
必须显示class?class_id=55
数据,但在我的class?class_id=55
班级中则显示班级?class_id = 47类数据。
我的控制器:
public function getclass(Request $request)
{
$id = $request->get('class_id'); if(Input::has('status-text'))
{
$text=e(Input::get('status-text'));
$rules = [
'status_text'=>'required|string',
];
$validator = Validator::make($request->all(), $rules);
if(Input::hasFile('status_image_upload'))
{
$rules['status_image_upload'] = 'image';
$validator = Validator::make($request->all(), $rules);
if($validator->fails())
{
$image = $request->file('status_image_upload');
$imageName = str_random(8).'_'.$image->getClientOriginalName();
$image->move('status_images', $imageName);
$userStatus = new Status();
$userStatus -> class_id = $id;
$userStatus -> status_text = $text;
$userStatus -> image_url = $imageName;
$userStatus -> type = 1;
$userStatus -> users_id = Auth::user()->id;
$userStatus -> save();
Flash::success('Your status has been posted');
return redirect(route('class',['class_id'=>$id]));
}
}
else if ($validator->fails())
{
$userStatus = new Status();
$userStatus -> class_id = $id;
$userStatus -> status_text = $text;
$userStatus -> video_url = $request['video_url'];
$userStatus -> type = 2;
$userStatus -> users_id = Auth::user()->id;
$userStatus -> save();
Flash::success('Your status has been posted');
return redirect(route('class',['class_id'=>$id]));
}
}return view('class',[
'posts'=>status::orderBy('id','DESC')->get()
])->with('class_id',$request->get('class_id'))
->with('classroom',classroomModel::find($id)->first());}
我的观点
<li>Subject-->{{$classroom->subject_name}}</li>
<li>Section-->{{$classroom->section}}</li>
应该怎么做?