<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
balfour / eloquent-dynamic-relationships example snippets
namespace SMSModule;
use Balfour\EloquentDynamicRelationships\HasDynamicRelationships;
use Illuminate\Database\Eloquent\Model;
class Message extends Model
{
use HasDynamicRelationships;
//
}
namespace SMSModule;
use Balfour\EloquentDynamicRelationships\Model;
class Message extends Model
{
//
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use SMSModule\Message;
use UserModule\User;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
UserModule::bond('messages', function () {
return $this->hasMany(Message::class);
});
}
}
use SMSModule\Message;
use UserModule\User;
$user = User::find(1);
// retrieve a user's messages
$messages = $user->messages;
// retrieve and sort a user's messages by send date
$messages = $user->messages()
->latest('send_date')
->get();
// paginate a user's messages
$messages = $user->messages()
->paginate();
// get the user who sent the message
$message = Message::first();
$user = $message->user;
use UserModule\User;
// destroy a bond between 2 models
User::breakup('activities');
// retrieve all dynamic bonds
$bonds = User::getBonds();
// determine if a model is bonded with another
User::isBondedWith('activities');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.