栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Laravel增删改查

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Laravel增删改查

代码
NewsController.php
orderBy('id','desc')->get();
        // dd($newsList);
        return view('news.index',compact('newsList'));
        //
    }

    
    public function create()
    {
        return view('news.addnews');
        //
    }

    
    public function store(Request $request)
    {
        //name起作用,
        // dd($request->all());
        $data = $request->except('_token');
        $data['user_id']=1;
       $res = DB::table('news')->insert($data);
        if($res){
            return redirect('/news');
        }
        dd($data);
        //
    }

    
    public function show($id)
    {
        //
       $news = DB::table('news')->where('id',$id)->first();
        return view('news.show',compact('news'));
    }

    
    public function edit($id)
    {
        //
        $news = DB::table('news')->find($id);
        return view('news.edit',compact('news'));
    }

    
    public function update(Request $request, $id)
    {
        //
        $news = $request->except('_token','_method');
        // dd($news);
        $res =DB::table('news')->where('id',$id)->update($news);
        // dd($news,$res);
        return redirect('news');

    }

    
    public function destroy($id)
    {
        //
       $res = DB::table('news')->where('id',$id)->delete();
    //    dd($res);
        return redirect('news');
        
        
    }
}
show.php

@extends('layout.grail')
@section('title',$news->title)
@section('main')
https://blog.csdn.net/m0_64863890/article/details/{{$news->title}}

https://blog.csdn.net/m0_64863890/article/details/{{$news->user_id}}

https://blog.csdn.net/m0_64863890/article/details/{{$news->content}}
@endsection
index.php

@extends('layout.grail')
@section('title','新闻列表')
@section('main')

新闻列表

@foreach ($newsList as $news ) @endforeach
新闻id 新闻标题 用户id 种类id
https://blog.csdn.net/m0_64863890/article/details/{{$news->id}} https://blog.csdn.net/m0_64863890/article/details/{{$news->title}} https://blog.csdn.net/m0_64863890/article/details/{{$news->user_id}} https://blog.csdn.net/m0_64863890/article/details/{{$news->category_id}} 修改
@method('delete') @csrf
@endsection
添加信息


删除

修改

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/871640.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号