- https://speakerdeck.com/willroth/50-laravel-tricks-in-50-minutes
- https://www.reddit.com/r/laravel/comments/3to60i/50_laravel_tricks/
- 1. Automatic Model Validation
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
Route Controller: | |
//List Products | |
Route::get('products','ProductController@index'); | |
//List single Product | |
Route::get('product/{id}','ProductController@show'); | |
//Create new Product | |
Route::post('product','ProductController@store'); | |
//Update Product | |
Route::put('product','ProductController@store'); | |
//Delete Product |
public function connections()
{
$relation = $this
->belongsToMany(static::class, 'connections', 'requestor_id', 'requested_id')
->withTimestamps();
/// delete the already built inner join
$relation
->getQuery() // Eloquent\Builder
/* ******************************************************************************************* | |
* GLOBAL CONFIG | |
* Vue.config is an object containing Vue’s global configurations. | |
* You can modify its properties listed below before bootstrapping your application. | |
* https://vuejs.org/v2/api/#Global-Config | |
* ******************************************************************************************* */ | |
// Configure whether to allow vue-devtools inspection | |
Vue.config.devtools = true |
Allow display images and youtube video: | |
CSS class for links .htmllink and images .htmlimg | |
public function linkify($showimg = 1, $value, $protocols = array('http', 'mail', 'https'), array $attributes = array('target' => '_blank')) | |
{ | |
// Link attributes | |
$attr = ''; | |
foreach ($attributes as $key => $val) { | |
$attr = ' ' . $key . '="' . htmlentities($val) . '"'; | |
} |
function getVideoUrl($link){ | |
$data = explode('.mp4', $link); | |
$decode = urldecode($data[0]); | |
$linkDownload = array(); | |
$v1080p = $decode.'_hd.mp4'; | |
$v720p = $decode.'_dvd.mp4'; | |
$v360p = $decode.'_fmt1.ogv'; | |
$linkDownload['1080p'] = $v1080p; | |
$linkDownload['720p'] = $v720p; | |
$linkDownload['360p'] = $v360p; |
/* | |
<a href="posts/2" data-method="delete"> <---- We want to send an HTTP DELETE request | |
- Or, request confirmation in the process - | |
<a href="posts/2" data-method="delete" data-confirm="Are you sure?"> | |
*/ | |
(function() { |
in database: | |
$table->enum('fruit', ['apple', 'banana', 'cantalope']); | |
in controller's construct: | |
public function __construct() | |
{ | |
DB::getDoctrineSchemaManager()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); | |
} | |
how to use this Enum in cotroller: |