Skip to content

Instantly share code, notes, and snippets.

View FrankFlow's full-sized avatar

FrankFlow FrankFlow

View GitHub Profile
<?php
// access route names as tenant.account.profile.* e.g. tenant.account.profile.edit
// access route path as account/profile/* e.g. account/profile/edit
Route::group(['prefix' => 'profile'], function () {
Route::get('/', 'ProfileController@edit')->name('profile.edit'); // show profile edit form
Route::patch('/', 'ProfileController@update')->name('profile.update'); // edit profile
});
<php
dd(
optional(App\User::find(2)->avatars)->path_avatar
);
<?php
$user = App\User::find(2);
return $user->avatars ? $user->avatars->path_avatar : '';
<?php
// App/User
public function avatars()
{
return $this->hasOne('App\Avatar');
}
<?php
$inItaly = collect($hosts)
->where('location', 'Italy')
->when(request('retired'), function($collection) {
return $collection->reject(function($employee){
return $employee['is_active'];
});
});
<?php
$inItaly = collect($hosts)->where('location', 'Itaky');
if (request('retired')) {
$inItaly = $inItaly->filter(function($employee){
return ! $employee['is_active'];
});
}
<?php
$hosts = [
['name' => 'Francesco Lettera', 'location' => 'Italy', 'is_active' => 0],
['name' => 'Mario Rossi', 'location' => 'Italy', 'is_active' => 0],
['name' => 'Giuseppe Giacobini', 'location' => 'Italy', 'is_active' => 1]
];
<?php
@editor
<a href="{{ route('super.secret') }}">Secret Page</a>
@else
Welcome Guest. <a href="{{ route('login') }}">Login</a>
@endeditor
<?php
use Illuminate\Support\Facades\Blade;
Blade::if('editor', function () {
return auth()->check() && auth()->user()->isEditor();
});
<?php
use Illuminate\Contracts\Validation\ImplicitRule;
class MiaValidationRule implements ImplicitRule
{
public function passes($attribute, $value)
{
return $value > 10;
}