You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i have one to may relationship between pharmacy and pharmacy Branch respectively.
`<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePharmaciesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pharmacies', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('branches');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('pharmacies');
}
}
`
`<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePharmacyBranchesTable extends Migration
{
/**
* Run the migrations.
*
@return void
*/
public function up()
{
Schema::create('pharmacy_branches', function (Blueprint $table) {
$table->id();
$table->bigInteger('p_id')->unsigned();
$table->double('lat', 9, 6);
$table->double('long', 9, 6);
$table->timestamps();
@return void
*/
public function down()
{
Schema::dropIfExists('pharmacy_branches');
}
}
` PharmacyBranch model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class PharmacyBranch extends Model
{
use HasFactory;
public function pharmacy()
{
return $this->belongsTo(Pharmacy::class,'p_id');
}
}
Pharmacy Model
`<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Pharmacy extends Model
{
use HasFactory;
public function branches()
{
return $this->hasMany(PharmacyBranch::class);
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
i have one to may relationship between pharmacy and pharmacy Branch respectively.
`<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePharmaciesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pharmacies', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->integer('branches');
}
`
`<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreatePharmacyBranchesTable extends Migration
{
/**
* Run the migrations.
*
@return void
*/
public function up()
{
Schema::create('pharmacy_branches', function (Blueprint $table) {
$table->id();
$table->bigInteger('p_id')->unsigned();
$table->double('lat', 9, 6);
$table->double('long', 9, 6);
$table->timestamps();
}
/**
*/
public function down()
{
Schema::dropIfExists('pharmacy_branches');
}
}
`
PharmacyBranch model
Pharmacy Model
`<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Pharmacy extends Model
{
use HasFactory;
}
`
the error I get in tinker.
`>>> PharmacyBranch::find(9)->pharmacy
=> null
Beta Was this translation helpful? Give feedback.
All reactions