1. Go to this page and download the library: Download shayanys/lara-reserve library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shayanys / lara-reserve example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use ShayanYS\LaraReserve\Interfaces\ReservableInterface;
use ShayanYS\LaraReserve\Models\Reserve;
use ShayanYS\LaraReserve\Traits\Reservable;
class Book extends Model implements ReservableInterface
{
use HasFactory, Reservable;
}
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use ShayanYS\LaraReserve\Interfaces\CustomerInterface;
use ShayanYS\LaraReserve\Traits\Customer;
class User extends Authenticatable implements CustomerInterface
{
use HasApiTokens, HasFactory, Notifiable, Customer;
}
$airplaneSeat = AirplainSeat::first();
$customer = User::first();
$airplaneSeat->withoutCheckAvailability()->reserveForCustomer($customer,now()->addDay(),'00:00:00',metadata:['code' => 123]);
//or call reserve method of customer like this:
$customer->reserve($airplaneSeat->withoutCheckAvailability(),now()->addDay(),'00:00:00',metadata:['key' => 'value']);
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use ShayanYS\LaraReserve\Interfaces\ReservableInterface;
use ShayanYS\LaraReserve\Models\Reserve;
use ShayanYS\LaraReserve\Traits\Reservable;
class AirplaneSeat extends Model implements ReservableInterface
{
use HasFactory,Reservable;
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
$this->checkAvailability = false;
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use ShayanYS\LaraReserve\Interfaces\ReservableInterface;
use ShayanYS\LaraReserve\Models\Reserve;
use ShayanYS\LaraReserve\Traits\Reservable;
class AirplaneSeat extends Model implements ReservableInterface
{
use HasFactory,Reservable;
public function shouldCheckAvailability() : bool{
// TODO: Implement shouldCheckAvailability() method.
return false;
}
}
$airplaneSeat = AirplainSeat::first();
$customer = User::first();
$airplaneSeat->withCheckAvailability()->reserveForCustomer($customer,now()->addDay(),'00:00:00',metadata:['code' => 123]);
//or call reserve method of customer like this:
$customer->reserve($airplaneSeat->withCheckAvailability(),now()->addDay(),'00:00:00',metadata:['key' => 'value']);
$airplaneSeat = AirplainSeat::first();
$customer = User::first();
$airplaneSeat->activeReserves()->get();
// this will return collection of active reserves which reserved this reservable
//(the reservations that have a reserved date and time or end reservation date and time that are greater than or equal to the current date and time.)
$customer->activeReserves()->get();
// this will return collection of active reserves which reserved by this customer
//(the reservations that have a reserved date and time or end reservation date and time that are greater than or equal to the current date and time.)
$airplaneSeat = AirplainSeat::first();
$customer = User::first();
$airplaneSeat->allReserves()->get();
// this will return collection of all reserves which reserved this reservable
$customer->allReserves()->get();
// this will return collection of all reserves which reserved by this customer
$airplaneSeat = AirplainSeat::first();
$customer = User::first();
$airplaneSeat->startedReserves()->get();
// this will return collection of started reserves which reserved this reservable
//(the reservations that have a reserved date and time that are greater than or equal to the current date and time and end reservation date and time less than current date and time.)
$customer->startedReserves()->get();
// this will return collection of started reserves which reserved by this customer
//(the reservations that have a reserved date and time that are greater than or equal to the current date and time and end reservation date and time less than current date and time.)
$airplaneSeat = AirplainSeat::first();
$customer = User::first();
$airplaneSeat->endedReserves()->get();
// this will return collection of ended reserves which reserved this reservable
//(the reservations that have a end reservation date and time that are greater than current date and time)
$customer->endedReserves()->get();
// this will return collection of ended reserves which reserved by this customer
//(the reservations that have a end reservation date and time that are greater than current date and time)
shell
php artisan migrate
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.