laravel简说
作者:互联网
参数传递: $name=[ 'a' 'b' 'c' ]; $age=30; return view('view',['name'=>$name,'age'=>$age,'say'=>'hello']); return view('view')->with('name',$name)->with('age',$age)->with('say','hello'); say='hello'; return view('view',compact('name','age','say')); 数据库基础 --1----------------------------------- $body=DB:table('blogs')->get(); //$body=App\blog::all() return $body; --2----------------------------------- $body=DB::table('blogs')->get(); return view('welcome',compact('body')); --html----------------------------------- @foreach($body as $body) {{ $body->title }} @endforeach url传参 Route::get('/{id}', function ($id) { //dd($id); $body=DB::table('blogs')->Where('id',$id)->get(); //$bodyblog::where('id','<' ,'3')->get() return view('welcome',compact('body')); }); Route::get('/{id}/{bodyid}', function ($id,$bodyid) { dd($id,$bodyid); }); Route::get('/{id}/{bodyid}', function ($id,$bodyid) { //dd($id,$bodyid) $body=DB::table('blogs')->find($id); //$body=App\blog::find($id); dd($body); }); Route::get('/{id}/{bodyid}', function ($id,$bodyid) { //dd($id,$bodyid) $body=DB::table('blogs')->find($id); //find返回为字符,前台不能用foreach,直接{{ $body-title }}输出即可 // dd($body); return view('welcome',compact('body')); }); 写入基础 $blog=new App\blog; $blog->title='titile'; $blog->body='body'; $blog->save(); 控制 public function show(blog $blog) 对应 Route::get('/{blog}',BlogController@show); view <form action="/blogpost" method="post"> @csrf <label>title</label> <input type="text" id="title" name="title"> <label>title</label> <textarea id="body" name="body"></textarea> </form> 路由 Route::post('/blogpost','BlogController@store'); 控制 $blog=new /App/blog; $blog->title=request('title'); $blog->body=request('body'); $blog->save(); 自定义显示时间 {{ date ("F j, Y, G:i", strtotime($blogs->created_at)) }}
标签:laravel,body,get,bodyid,blog,简说,id,view 来源: https://blog.51cto.com/u_15181826/2734350