Skip to content

Instantly share code, notes, and snippets.

View Mombuyish's full-sized avatar
Never stop progressing.

Yish Mombuyish

Never stop progressing.
View GitHub Profile
<?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
<?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
<?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
<?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 April 14, 2018 09:17
route methods
<?php
/*
* 渲染頁面
* resources/views/pages/about.blade.php
*/
// 原始
Route::get('/about', function() {
return view('pages.about');
<?php
$client = new \GuzzleHttp\Client();
$response = $client->request('POST', 'https://api.imgur.com/3/image', [
'headers' => [
'authorization' => 'Client-ID ' . 'app_id',
'content-type' => 'application/x-www-form-urlencoded',
],
'form_params' => [
'image' => base64_encode(file_get_contents($request->file('image')->path()))
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.imgur.com/3/image');
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . 'app_id'));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, base64_encode(file_get_contents($request->file('image')->path())));
$response = curl_exec($curl);
<?php
namespace App;
class MemberLog extends Model
{
protected $table = 'cs_member_visit_log';
protected $guarded = [];
<?php
namespace App\Controllers;
use App\MemberLog;
class MemberLogController extends Controller
{
protected $model;
<?php
public function create($attributes)
{
$typein = in_array($attributes['type'], ['SignUp', 'ShareVideo', 'Subscription']);
$existLog = $typein && $this->existLogs($attributes['type']);
$doSomething = $this->doSomething($attributes['type']);
if ($existLog OR $doSomething) {
throw new GetLimitTimesException('Oops! it\'s get in limit.');