Skip to content

Instantly share code, notes, and snippets.

@me7media
me7media / laravel request remove parameter
Created July 8, 2020 13:35
laravel request remove parameter
GET parameter
request()->query->remove('key');
POST parameter
request()->request->remove('key');
@me7media
me7media / install postman to ubuntu
Created March 23, 2020 10:14
Ubuntu install Postman
wget https://dl.pstmn.io/download/latest/linux64 -O postman.tar.gz
sudo tar -xzf postman.tar.gz -C /opt
rm postman.tar.gz
sudo ln -s /opt/Postman/Postman /usr/bin/postman
@me7media
me7media / hasOne relation error laravel
Last active March 11, 2020 15:45
laravel must return a relationship instance
//this is example how to return a relationship instance in laravel if u have some logic to get it or troubles
public function user()
{
$id = ///some code to get $id
return $this->hasOne(User::class, 'id', 'id') // this just for new hasOne instance
->orWhere('id', $id); //get your niddle instanse
}
//Client model
private $notSaleSections = ['ТПМ-УПП', 'ТПМ-МДФ'];
public function saleParams()
{
return $this->hasMany(ClientParameter::class, 'customer', 'id')
->whereHas('param', function ($q) {
$q->where('section', null);
foreach ($this->notSaleSections as $s){
$q->orWhere('section', '!=', $s);
@me7media
me7media / Laravel User Roles Permissions through Middleware
Last active February 3, 2020 15:55
Laravel User Roles Permissions through Middleware
//Kernel
'permission' => \App\Http\Middleware\Permissions::class,
//Middleware\Permissions
public function handle($request, Closure $next, $permission = '')
{
if (!$request->user() || !$request->user()->hasPermission($permission)) {
return redirect('/');
}
return $next($request);
@me7media
me7media / yarn install SyntaxError: Unexpected token
Created January 16, 2020 23:00
yarn install /usr/local/lib/node_modules/yarn/lib/cli.js:46099 let { ^ SyntaxError: Unexpected token {
sudo npm --global install [email protected]
curl -sSL https://raw.githubusercontent.com/DefaultValue/ubuntu_post_install_scripts/master/ubuntu_18.04.sh | sh
@me7media
me7media / Laravel User Roles Permissions
Created October 1, 2019 14:14
Laravel User Roles Permissions
<?php
namespace App\Providers;
use App\Permission;
use Cache;
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
@me7media
me7media / Laravel Multilevel Menu
Created January 22, 2019 12:30
Laravel Multilevel Menu with js
//Controller Category - ['id', 'parent_id', 'name']
$categories = Category::all();
//menu.balde.php
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Catalog
</button>
<div class="dropdown-menu mainMenu" aria-labelledby="dropdownMenu2">
</ul>
<div class="childMenu">
@me7media
me7media / Laravel Получение товаров категории и ее дочерних категорий с условиями
Created January 18, 2019 14:29
Получение товаров категории и ее дочерних категорий с условиями
$products = null;
Category::whereId($category_id)->with([
'products' => function ($q) use (&$products, $search) {
$products = $q->where('active', true)
->search($search) //Scope
->get()
->unique();
},
'childrens.products' => function ($q) use (&$products, $search) {