git reset --soft HEAD^
This will reset your index to HEAD^ (the previous commit) but leave your changes in the staging area.$query = ...->orHaving('col1', 'like', %text%)->orHaving('col2', '=', 123);
$this->removeHaving('col1', $query); //removes it entirely
This code works for all ->having
, orHaving
, havingRaw
and orHavingRaw
public function removeHaving(Builder $builder, $havingColumn)
{
$bindings = $builder->getQuery()->bindings['having'];
$havings = $builder->getQuery()->havings;
if($havings){
$havingKey = false;
$isRaw = false;
foreach ($havings as $key => $having) {
if (isset($having['column']) && $having['column'] == $havingColumn) {
$havingKey = $key;
break;
}elseif(isset($having['type']) && $having['type'] === "Raw" && stripos($having['sql'], $havingColumn) !== false){
$isRaw = true;
$pattern = '/(or|and|(?:(?P<case1namE>)\() ?|) ?\w*(\.)?'.$havingColumn.'( like| ?\=) ?\?(?:(?P=case1namE) OR)?( and)?/mi';
$havings[$key]['sql'] = preg_replace($pattern, '', $having['sql']);
unset($bindings[$key]);
}
}
if ($havingKey !== false && !$isRaw) {
unset($bindings[$havingKey]);
unset($havings[$havingKey]);
}
$havings = empty($havings) ? null : $havings;
$builder->getQuery()->havings = $havings;
$builder->getQuery()->bindings['having'] = $bindings;
}
return $builder;
}
public function show(\App\Post $post)
{
$post->load('comments');
return view('posts.show', compact('post'));
}
also possible to load relation on every model instance with protected $with = ['comments'];
ctrl
+ shift
+ p
, type settings
and select Preferences: Open Settings (JSON)
to open "User settings", and add this:"editor.renderIndentGuides": false,
public function words()
{
return $this->belongsToMany('App\Word', definition_word)->withTimestamps();
}
Use this:
With a variable $table
we can use words()
function to the different tables.
public function words($table = null)
{
return $this->belongsToMany('App\Word', $table)->withTimestamps();
}
user_id
column on the books_chapter
table references the id
column on a users
table:
$table->foreign('book_id')->references('id')->on('books');
$table->foreign('chapter_id')->references('id')->on('texts');
$table->foreign('user_id')->references('id')->on('users');
->onDelete('cascade')
helps us to automatically delete related rows in Laravel
$table->foreign('book_id')->references('id')->on('books')->onDelete('cascade');
$table->foreign('chapter_id')->references('id')->on('texts')->onDelete('cascade');
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
class User extends Model {
protected $fillable = ['name', 'email', 'mobile'];
// All fields inside $fillable array can be mass-assigned
}