iachievedream / blog-laravel Goto Github PK
View Code? Open in Web Editor NEW說明筆記:https://hackmd.io/@JvzyHmrLSNCa2tYaMCOzxQ/By9oCCU7L
說明筆記:https://hackmd.io/@JvzyHmrLSNCa2tYaMCOzxQ/By9oCCU7L
Request 的參數差異,兩個參數都能使用,只有Request也可以執行update。
public function update(Request $request, Article $article)
public function update(Request $request, $id)
public function update(Request $request)
laravel在Article::create何時使用下方兩關鍵字,
'title'以及title的使用以及差異還不了解。
'title'這個不知怎麼了解,
以及'title' => $request->title,的順序。
現有我知道的,
title是字串,
$title是變數,
'$title'顯示的數值是輸入變數本身,
"$title"顯示的數值是變數的數值,
=>是使用在array,
->是使用在object,
$this是參照變數(reference)。
//方法
$article = Article::create([
'title' => $request->title,
'content' => $request->content,
'author' => Auth::user()->name,
]);
//物件導向
// $article = new Article([
// 'title' => $request->title,
// 'content' => $request->content,
// 'author' => Auth::user()->name,
// ]);
// //error:Class name must be a valid object or a string
// $title = $request->title;
// $content = $request->content;
// $article = new Article();
// $article->title = $title;
// $article->content = $content;
// $article->Auth::user()->name = $author;
//打印
// dd($article);
//打印型態
// dd(gettype(Auth::user()-> name));
Controller抓取Model的數據,數據再從Model由DB取出,
但Model以及DB的table是不同的(相差一個s),
不知如何取到資料。
protected $table = 'users'; // 資料表抓取資料
protected $fillable = [ // 修改或是更新資料需要用fillable(可填充)的功能
'name', 'email', 'password',
];
Controller.php
public function index()
{
$article = Article::all();
return view('article.index')->with('article',$article);
}
with('1',$2)
沒有1是顯示錯誤碼:Illegal offset type,
沒有2是顯示錯誤碼:Trying to get property 'id' of non-object
2,1有順序問題,顛倒錯誤碼:Illegal offset type
view>>article/index.php
@foreach($article as $article)
{{$article->title}}
@endforeach
手冊(預載入):https://laravel.tw/docs/5.1/eloquent-relationships
有$字號變數以及'單引號'分不清楚狀況,
已經有用article以及articles做測試功能,但還是無法分辨清楚。
public function update(Request $request,$id)
{
// dd($request->tltle); //沒數值
$title = $request->title;
dd($title); //有數值,使用變數帶入
$content = $request->content;
$author = Auth::user()->name;
// dd($author);
$db = DB::table('articles')->where('id',$id)
->update(['title'=>$title,'content'=>$content]);
// dd("$db"); // 如何確認且打印更新的數據出來,直接結果是更新成功,但不了解過程
return redirect('/');
}
array的使用需要[、]。
統一更新
->update(['title'=>$title,'content'=>$content]);
分開更新
->update(['title'=>$title],['content'=>$content]);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.