第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何打印 id 特定數(shù)據(jù)?

如何打印 id 特定數(shù)據(jù)?

PHP
慕森卡 2022-01-24 10:08:24
我正在嘗試打印與我的餐廳相關(guān)的菜肴。每道菜都分配了一個(gè)restaurant_id。每個(gè)餐廳都分配了一個(gè)ID.餐廳遷移Schema::create('restaurants', function (Blueprint $table) {        $table->bigIncrements('id');        $table->string('name');        $table->timestamps();});盤遷移Schema::create('dishes', function (Blueprint $table) {        $table->bigIncrements('id');        $table->string('name');        $table->float('price');        $table->integer('restaurant_id');        $table->string('image');        $table->timestamps();});餐廳播種機(jī)DB::table('restaurants')->insert([        'name' => 'Bellos Pizzeria',        'updated_at' => DB::raw('CURRENT_TIMESTAMP'),    ]);    DB::table('restaurants')->insert([        'name' => 'McDonalds',        'updated_at' => DB::raw('CURRENT_TIMESTAMP'),    ]);    DB::table('restaurants')->insert([        'name' => 'Ericos',        'updated_at' => DB::raw('CURRENT_TIMESTAMP'),    ]);播種機(jī)    DB::table('dishes')->insert([        'name' => 'Butter Chicken',        'price' => '12',        'restaurant_id' => 1,        'image' => 'dishes_images/default.png',        'updated_at' => DB::raw('CURRENT_TIMESTAMP'),    ]);    DB::table('dishes')->insert([        'name' => 'Hamburger',        'price' => '10',        'restaurant_id' => 2,        'image' => 'dishes_images/default.png',        'updated_at' => DB::raw('CURRENT_TIMESTAMP'),    ]);個(gè)別餐廳視圖上的 html@section('content')    <h1> {{$restaurant->name}} </h1>    <a href="/assignment2/public/restaurant"> back </a>@endsection  我正在嘗試打印與餐廳相關(guān)的菜肴。例如,id=1將在餐廳“Bellos Pizzeria”( ) 中列出的“Butter Chicken” ( id=1)。
查看完整描述

2 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

在Restaurant模型中編寫關(guān)系代碼。看到你上面的問題,我明白這種關(guān)系是一對多的關(guān)系。在這種情況下,請?jiān)诓蛷d模型中寫下這個(gè)。


餐廳.php


public function dishes(){

    return $this->hasMany(Dish::class);

    //it define the relation type between Restaurant and Dish model

}

刀片文件


<h1> {{$restaurant->name}} </h1>


<ul>

    @foreach($restaurant->dishes as $dish)

        <li>{{ $dish->name }}</li>

    @endforeach

</ul>

$restaurant->dishes將返回與餐廳相關(guān)的所有相關(guān)菜肴的數(shù)組/集合。用于@foreach顯示所有菜肴。


用戶自己的Html,我用ul li的例子。


查看完整回答
反對 回復(fù) 2022-01-24
?
莫回?zé)o

TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊

您應(yīng)該嘗試使用 laravel 關(guān)系。喜歡


創(chuàng)建Restaurants和Dishes建模。


在您的餐廳模型中:


class Restaurants extends Model

{

    function dishes() {

      return $this->hasMany('App\Dishes');

    }

}

在您的菜肴模型中


class Dishes extends Model

{

    function restaurants() {

      return $this->hasMany('App\Restaurants');

    }

}


查看完整回答
反對 回復(fù) 2022-01-24
  • 2 回答
  • 0 關(guān)注
  • 151 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號