DEV Community

Mostafa Jamali
Mostafa Jamali

Posted on

implements of the OOP concepts in Laravel

 Hello everyone, I hope you are healthy. Usually, I've confused about how to follow OOP rules as using Laravel! for example how to follow SOLID rules with the framework.
Enter fullscreen mode Exit fullscreen mode

For example, I want to build a simple marketplace for a company and I follow this method.
For example for the invoicement part :
1- First, I created an interface for it.
Code:
InvoiceIf.php->
<?php
namespace App\Classes\Interfaces;
interface InvoiceIf
{
public function customer();
public function sellerUsers();
public function products();
public function prices();
}

Then, I've created a Eloquent Model like:
Invoice.php
<?php
namespace App\Classes;
use Illuminate\Database\Eloquent\Model;
use App\Classes\SellerUser;
class Invoice extends Model implements InvoiceIf
{
final public function customer()
{
return $this->hasOne(Customer::class);
}
final public function sellerUsers()
{
return $this->hasMany(SellerUser::class);
}
final public function products()
{
return $this->hasMany(Product::class);
}
final public function prices()
{
return $this->hasMany(Price::class);
}

}
Third, I create a Controller to handle user requirements.
but in this time, this method that I've followed it is true or not?
please help me...

Top comments (0)