class SugController extends Controller
{
//添加数据
public function add(Request $request){
$data['sug_name'] = $request->name;
$data['sug_radio'] = $request->radio;
$data['sug_file'] = $request->file('file')->store('img');
$data['sug_text'] = $request->text;
if (SugModel::add($data)){
return "<script>alert('数据添加成功')</script>".redirect()->action('SugController@show');
}
}
//展示数据
public function show(){
$data = SugModel::show();
return view('show', ['data' => $data]);
}
//删除数据
public function del($id){
if ( SugModel::del($id)){
return "<script>alert('数据删除成功')</script>".redirect()->action('SugController@show');
}elseif (!empty($id)){
return "<script>alert('id不能为空')</script>".redirect()->action('SugController@show');
}
}
//修改数据
public function updates($id){
$data = SugModel::updates($id);
return view('update', ['data' => $data]);
}
//开始修改数据
public function up(Request $request){
$data['sug_name'] = $request->name;
$data['sug_radio'] = $request->radio;
$data['sug_text'] = $request->text;
$id = $request->id;
if ( SugModel::up($data,$id)){
return "<script>alert('数据修改成功')</script>".redirect()->action('SugController@show');
}else{
return "<script>alert('数据修改失败')</script>".redirect()->action('SugController@show');
}
}
}
lavavel 框架的增删改查 C层
猜你喜欢
转载自blog.csdn.net/zhouqi1427/article/details/108616025
今日推荐
周排行