Relationship - ServiceCategory and Service

Posted 5 months ago by siusiak1000

Hello! I have services and a category of services. I can not deal with relationships. How to do it.? Do I have to use a pivot table or can I solve it differently? If so, where can I save the relationship?

ServiceCategory - model

class ServiceCategory extends Model
{
    public $fillable = ['name', 'order'];

}

ServiceCategory - migration

        Schema::create('service_categories', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->integer('order')->default(0);
            $table->timestamps();
        });

Service - Model

class Service extends Model
{
    protected $fillable = [
        'name',
        'category',
        'position',
        'duration',
        'price',
        'old_price',
        'vat',
        'promotion',
        'public_desc',
        'private_desc',
        'photo',
    ];

}

ServiceController

        $service = Service::create([
            'name' => $request->name,
            'category' => $request->category,
            'position' => $request->position,
            'duration' => $request->duration,
            'price' => $request->price,
            'old_price' => $request->old_price,
            'vat' => $request->vat,
            'promotion' => $request->promotion,
            'public_desc' => $request->public_desc,
            'private_desc' => $request->private_desc,
            'photo' => $name_photo,
        ]);
$service->save();

Service - migration

        Schema::create('services', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('category');
            $table->integer('position');
            $table->integer('duration');
            $table->float('price');
            $table->float('old_price');
            $table->integer('vat');
            $table->boolean('promotion')->nullable();
            $table->text('public_desc');
            $table->text('private_desc');
            $table->string('photo');
            $table->timestamps();
        });

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.