Skip to content

Instantly share code, notes, and snippets.

🚀
Rock and Roll

Yish Mombuyish

🚀
Rock and Roll
Block or report user

Report or block Mombuyish

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View vuepress.sh
# install
npm install -g vuepress
# create a markdown file
echo '# Hello VuePress' > README.md
# start writing
vuepress dev
# build to static files
View request.php
<?php
// passing array.
public function store(Request $request)
{
$data = $request->all();
//array_set, array_add and others way.
array_set($data, 'status', 'draft');
// accept array.
View optional.php
<?php
// User 1 exists, with account
$user1 = User::find(1);
$accountId = $user1->account->id; // 123
// User 2 exists, without account
$user2 = User::find(2);
$accountId = $user2->account->id; // PHP Error: Trying to get property of non-object
View abort_if.php
<?php
abort_if(! Auth::user()->isAdmin(), 403);
abort_if(! Auth::user()->isAdmin(), 403, 'Sorry, you are not an admin');
abort_if(Auth::user()->isCustomer(), 403);
// In "admin" specific controller
public function index()
{
if (! Auth::user()->isAdmin()) {
View route_model.php
<?php
class Burger extends Model
{
public function getRouteKeyName()
{
return 'slug';
}
}
View route_advance.php
<?php
Route::domain('{location}.example.com')->group(function () {
Route::get('employees/{id}/{name}', 'EmployeesController@show')->name('employees.show');
});
route('employees.show', ['location' => 'raleigh', 'id' => 5, 'name' => 'chris']); // http://raleigh.example.com/employees/5/chris
View route.php
<?php
Route::get('burgers', 'BurgersController@index')->name('burgers');
route('burgers'); // http://example.com/burgers
route('burgers', ['order_by' => 'price']); // http://example.com/burgers?order_by=price
Route::get('burgers/{id}', 'BurgersController@show')->name('burgers.show');
route('burgers.show', 1); // http://example.com/burgers/1
route('burgers.show', ['id' => 1]); // http://example.com/burgers/1
View str_plural.php
<?php
str_plural('dog'); // dogs
str_plural('cat'); // cats
str_plural('dog', 2); // dogs
str_plural('cat', 1); // cat
str_plural('child'); // children
str_plural('person'); // people
View data_get.php
<?php
$array = ['albums' => ['rock' => ['count' => 75]]];
$count = data_get($array, 'albums.rock.count'); // 75
$avgCost = data_get($array, 'albums.rock.avg_cost', 0); // 0
$object->albums->rock->count = 75;
$count = data_get($object, 'albums.rock.count'); // 75
@Mombuyish
Mombuyish / web.php
Created Apr 14, 2018
route methods
View web.php
<?php
/*
* 渲染頁面
* resources/views/pages/about.blade.php
*/
// 原始
Route::get('/about', function() {
return view('pages.about');
You can’t perform that action at this time.