Put SearchTrait.php in app directory. Then use SearchTrait in your model, like so
use App\SearchTrait;
use Illuminate\Database\Eloquent\Model;
class Article extends Model {| <?php | |
| /** | |
| * Dumps a given variable along with some additional data. | |
| * | |
| * @param mixed $var | |
| * @param bool $pretty | |
| */ | |
| function dd($var, $pretty = false) | |
| { |
| <?php | |
| // Examples for URL: https://example.com/subFolder/yourfile.php?var=blabla#12345 | |
| //built-in function | |
| $x = parse_url($url); | |
| $x['scheme'] 🡺 https | |
| $x['host'] 🡺 example.com (or with WWW) | |
| $x['path'] 🡺 /subFolder/yourfile.php | |
| $x['query'] 🡺 var=blabla | |
| $x['fragment'] 🡺 12345 // hashtag outputed only in case, when hashtag-containing string was manually passed to function, otherwise PHP is unable to recognise hashtags in $_SERVER |
| # delete local tag '12345' | |
| git tag -d 12345 | |
| # delete remote tag '12345' (eg, GitHub version too) | |
| git push origin :refs/tags/12345 | |
| # alternative approach | |
| git push --delete origin tagName | |
| git tag -d tagName |
| <?php | |
| // Usage: | |
| // Before | |
| @if ($errors->has('email')) | |
| <span>{{ $errors->first('email') }}</span> | |
| @endif | |
| // After: |
| desc: | |
| In addition, if the current time is less than 30 minutes from endhour, expired is also counted as expired. | |
| Array | |
| ( | |
| [0] => Array | |
| ( | |
| [date] => 2019-06-01 | |
| [week] => Saturday | |
| [subdate] => 06-01 |
| <?php | |
| /* | |
| Class for reading and writing array data in json format | |
| Author: Sarfraz Ahmed ([email protected]) | |
| */ | |
| class JsonTexter | |
| { | |
| protected $file = null; | |
| public function __construct($file) |
| <?php | |
| use Illuminate\Database\Query\Builder; | |
| Builder::macro('orderByNulls', function ($column, $direction = 'asc', $nulls = 'last', $bindings = []) { | |
| $column = $this->getGrammar()->wrap($column); | |
| $direction = strtolower($direction) === 'asc' ? 'asc' : 'desc'; | |
| $nulls = strtolower($nulls) === 'first' ? 'NULLS FIRST' : 'NULLS LAST'; | |
| return $this->orderByRaw("$column $direction $nulls", $bindings); | |
| }); |
| <?php | |
| use Illuminate\Database\Eloquent\Builder as EloquentBuilder; | |
| use Illuminate\Database\Query\Builder as QueryBuilder; | |
| use Illuminate\Database\Query\Expression; | |
| use Illuminate\Support\ServiceProvider; | |
| class AppServiceProvider extends ServiceProvider | |
| { | |
| public function boot() |