Coder Social home page Coder Social logo

blog-laravel's People

Contributors

dependabot[bot] avatar iachievedream avatar

Watchers

 avatar  avatar

blog-laravel's Issues

Request 的參數使用以及差異性

Request 的參數差異,兩個參數都能使用,只有Request也可以執行update。

public function update(Request $request, Article $article) 
public function update(Request $request, $id)
public function update(Request $request)

'title'的解釋以及'title' => $request->title的順序關係如何看

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));

Mode以及DB的table名稱差異

Controller抓取Model的數據,數據再從Model由DB取出,
但Model以及DB的table是不同的(相差一個s),
不知如何取到資料。

     protected $table = 'users'; // 資料表抓取資料

    protected $fillable = [        // 修改或是更新資料需要用fillable(可填充)的功能
        'name', 'email', 'password',
    ];

I don't understand that with Laravel

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做測試功能,但還是無法分辨清楚。

update,dd()

    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]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.