1. Go to this page and download the library: Download mayankjanidev/laravel-store 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/ */
mayankjanidev / laravel-store example snippets
namespace App\Stores;
use Illuminate\Database\Eloquent\Builder;
use Mayank\Store\QueryStore;
use App\Models\Movie;
class TopRatedMovies extends QueryStore
{
public function query(): Builder
{
return Movie::orderByDesc('rating');
}
}
class TopRatedMoviesController extends Controller
{
public function index(TopRatedMovies $topRatedMovies)
{
$movies = $topRatedMovies->get();
...
}
}
$movies = (new TopRatedMovies)->get();
(new TopRatedMovies)->getCachedData();
(new TopRatedMovies)->cache();
(new TopRatedMovies)->clearCache();
class TopRatedMovies extends QueryStore
{
public function cacheKey(): string
{
return 'best-movies';
}
public function cacheDuration(): DateTime
{
return now()->addHours(2);
}
}
class TopRatedMovies extends QueryStore
{
public function cacheData(): Collection
{
return $this->query()->limit(250)->get();
}
}
(new TopRatedMovies)->paginate();
(new TopRatedMovies)->simplePaginate();
use Mayank\Store\CustomStore;
class Languages extends CustomStore
{
public function data(): array
{
return ['English', 'Spanish', 'French'];
}
}
class MovieObserver
{
public function updated(Movie $movie): void
{
(new TopRatedMovies)->clearCache();
}
}
class TopRatedMovies extends QueryStore
{
public function query(): Builder
{
return Movie::orderByDesc('rating');
}
public function getDataForApi(): Collection
{
return $this->query()->limit(10)->get();
}
}
class TopRatedMovies extends QueryStore
{
public function __construct(protected Country $country)
{
}
public function query(): Builder
{
return Movie::orderByDesc('rating')->where('country', $this->country->name);
}
}
sh
php artisan make:store TopRatedMovies --namespace=Data
sh
php artisan make:store Languages --custom
sh
php artisan store:clear TopRatedMovies
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.