This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="some-id"> | |
<category v-for="category in categories" | |
:id="category.id" | |
:name.sync="category.name" | |
</category> | |
// we add items to the categories array dynamically | |
<button @click="categories.push({})">Add categories</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Print query with bindings instead of '?' | |
*/ | |
function toRaw($query) | |
{ | |
return vsprintf(str_replace('?', "'%s'", $query->toSql()), $query->getBindings()); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Easily get route list in tinker | |
>>> app('RouteList')->setOption('method', 'PUT')->getRoutes() | |
>>> app('RouteList')->getRoutes()->where('name', 'website.login') | |
class RouteList extends \Illuminate\Foundation\Console\RouteListCommand | |
{ | |
/** @var array */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// controller | |
$course = Course::with(...)->checkEstablishmentOnView()->excludeArchived()->findOrFail($id); | |
$view = View::make('some.view')->with('course', $course); | |
return response()->json(['html' => $view->render()]); | |
// kahlan spec | |
it('does some magic and unicorns and all that stuff', function () { | |
allow(Double::classname(['class' => App\Course::class]))->toReceive('::with')->andReturn($query = Double::instance()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Presenters; | |
use ArrayAccess; | |
use Illuminate\Support\Collection; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Contracts\Pagination\Paginator; | |
class Decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user = User::find($user_id); | |
$user->branches->load([ | |
'roles' => function ($q) use ($user_id) { | |
$q->where('permissions_users.user_id', $user_id); | |
}, | |
'roles.permissions', | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Do this (explicit routes are better): | |
Route::get('qualification', function () {/**/}); | |
Route::get('qualification/{year}/{month}', function ($year, $month) {/**/}); | |
// You could also do this (but don't in your case): | |
// @link https://laravel.com/docs/5.6/routing#parameters-regular-expression-constraints | |
Route::get('qualification/{year_month?}', function ($year_month = null) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// assuming you want to get conv where last message doesn't come from the OP | |
Coversation::where('author_id', '!=', function ($q) { | |
$q->select('author_id')->from('messages')->whereRaw('conversation_id = conversations.id')->latest()->limit(1); | |
})->get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$ids = array_unique([1,2,3,4,5, ...]); | |
// relation() is HasMany | |
// check if all $ids belong to this parent model: | |
$parent_model->relation()->whereIn('id', $ids)->count() === count($ids) | |
// check if $ids match all of the children records: |
OlderNewer