laravel compact() and ->with()

后端 未结 7 1451
梦谈多话
梦谈多话 2020-11-30 07:17

I have a piece of code and I\'m trying to find out why one variation works and the other doesn\'t.

return View::make(\'gameworlds.mygame\', compact(\'fixture         


        
7条回答
  •  时光说笑
    2020-11-30 08:09

    Route::get('/', function () {
        return view('greeting', ['name' => 'James']);
    });
    
        
            

    Hello, {{ $name }}

    or

    public function index($id)
    {
        $category = Category::find($id);
        $topics = $category->getTopicPaginator();
        $message = Message::find(1);
    
        // here I would just use "->with([$category, $topics, $message])"
        return View::make('category.index')->with(compact('category', 'topics', 'message'));
    }
    

提交回复
热议问题