// Optional // Dingo Response Transformer $app['Dingo\\Api\\Transformer\\Factory']->setAdapter(function ($app) { $fractal = new League\Fractal\Manager(); $fractal->setSerializer(new League\Fractal\Serializer\JsonApiSerializer()); return new Dingo\Api\Transformer\Adapter\Fractal($fractal); }); // Dingo basic auth $app['Dingo\\Api\\Auth\\Auth']->extend('basic', function ($app) { return new Dingo\Api\Auth\Provider\Basic($app['auth'], 'phone'); }); // Dingo OAuth2.0 auth $app['Dingo\\Api\\Auth\\Auth']->extend('oauth', function ($app) { $provider = new Dingo\Api\Auth\Provider\OAuth2($app['oauth2-server.authorizer']->getChecker()); $provider->setUserResolver(function ($id) { return App\User::findOrFail($id); }); $provider->setClientResolver(function ($id) { // TODO // return OAuthClient::findOrFail($id); }); return $provider; }); // JWT OAuth app('Dingo\\Api\\Auth\\Auth')->extend('jwt', function ($app) { return new Dingo\Api\Auth\Provider\JWT($app['Tymon\\JWTAuth\\JWTAuth']); }); // Dingo Error Format $app['Dingo\\Api\\Exception\\Handler']->setErrorFormat(['error' => ['message' => ':message', 'errors' => ':errors', 'code' => ':code', 'status_code' => ':status_code', 'debug' => ':debug']]); /* |--------------------------------------------------------------------------
public function updateUser($id, $request) { $userModel = new \App\User(); $user = $userModel->findOrFail($id); try { $user->name = $request->get('name'); if ($request->changepass) { $user->password = \Hash::make($request->get('password')); } $user = $user->save(); } catch (\Exception $e) { dd($e); } }
public function testEditProfile() { $user = factory('App\\User')->create(); $this->actingAs($user); $this->put('/profile', ['firstname' => 'Ivan', 'lastname' => 'Ivanov'])->seeJson(['changed' => true]); $profile = App\User::findOrFail($user->id); $this->assertEquals('Ivan', $profile->firstname); $this->assertEquals('Ivanov', $profile->lastname); }
public function run() { // disable mysql foreigh key check if (config('database.default') == 'mysql') { DB::statement('SET FOREIGN_KEY_CHECKS=0;'); } /** * Setup config */ // Model $model = '\\App\\User'; // Table $table = 'role_user'; /** * TODO: Need to setup a config to enable and disable truncate */ // truncate Role table if (config('database.default') == 'mysql') { DB::table($table)->truncate(); } /** * * Attach Role - User * * -------------------------------------- */ // 1 App\User::findOrFail(1)->roles()->attach(1); // 2 App\User::findOrFail(2)->roles()->attach(2); /** * * END - Insert Data * * -------------------------------------- * -------------------------------------- */ // enable mysql foreigh key check if (config('database.default') == 'mysql') { DB::statement('SET FOREIGN_KEY_CHECKS=1;'); } }
/** * Get admin user from database. * * @return App\User * @throws Illuminate\Database\Eloquent\ModelNotFoundException */ protected function getSuperUser() { return App\User::findOrFail(1); }
Route::post('password/email', 'Auth\\PasswordController@postEmail'); // Password reset routes... Route::get('password/reset/{token}', 'Auth\\PasswordController@getReset'); Route::post('password/reset', 'Auth\\PasswordController@postReset'); Route::get('get/photo/{url}/{name}', ['as' => 'getPhoto', function ($url, $name) { $url_array = explode('.', $url); $storage_path = storage_path('app'); $path = $storage_path; for ($i = 0; $i < count($url_array); $i++) { $path .= '/' . $url_array[$i]; } //Append name to image path $path .= '/' . $name; if (!File::exists($path)) { return Image::make($storage_path . '/' . $url_array[0] . '/default.jpg')->response('jpg'); } return Image::make($path)->response(); }]); Route::get('get/view/{model}/{id}/{name}', ['as' => 'getView', function ($model, $id, $name) { $user = App\User::findOrFail($id); $obj = $user->{$model}; return view($name, [$model => $obj]); }]); Route::get('dev', function () { return 'For more projects like this, please contact me and we shall talk ;) <br/><br/> Joel Jeremy M. Marquez<br/> 09168882716<br/> joeljeremy.marquez@gmail.com or<br/> marquez_joeljeremy@yahoo.com<br/><br/> Thank you!'; });
// ※注意 // // Laravel5.2より上記controllerメソッドとcontrollersメソッドの両方共、 // 非推奨となった。今後はRoute::を使用し、個別に定義する必要がある。 // // 個別のルート定義 : // http://readouble.com/laravel/5/1/ja/authentication.html#included-routing // http://readouble.com/laravel/5/1/ja/authentication.html#resetting-routing // Route::get('who', function () { return 'こんにちは' . Request::input('name', '世界') . 'さん'; }); Route::get('who/{name}', function ($name) { return 'こんにちは' . $name . 'さん'; }); // 2.26 Route::get('all', function () { return App\User::all(); }); Route::get('find/{id}', function ($userId) { return App\User::find($userId); }); Route::get('find-or-404/{id}', function ($userId) { return App\User::findOrFail($userId); }); Route::get('update/{id}', function ($userId) { $user = App\User::findOrFail($userId); $user->name = 'Nomura'; $user->save(); return $user; });
| Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::group(['prefix' => 'api'], function () { Route::get('recipes', function () { return App\Recipe::with('ingredients')->get(); }); Route::get('recipes/{slug}', function ($slug) { return App\Recipe::where('slug', $slug)->with('ingredients')->firstOrFail(); }); Route::get('me/starred', function () { return App\User::findOrFail(1)->starred()->with('ingredients')->get(); }); Route::post('me/starred/{id}', function ($id) { App\User::findOrFail(1)->starred()->attach($id); return [(int) $id]; }); Route::delete('me/starred/{id}', function ($id) { App\User::findOrFail(1)->starred()->detach($id); return []; }); }); Route::get('{catchall}', function () { return view('app'); // This means all routes that don't begin with api/ will use the Angular app, which will take over with its own router })->where('catchall', '(.*)');
| Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */ Route::get('', function () { return View('index'); }); Route::get('/messages', 'MessageCtrl@index'); Route::get('/messages/{page}', 'MessageCtrl@indexPage')->where(['page' => '\\d+']); Route::post('/messages', 'MessageCtrl@store'); Route::delete('/messages/{id}', 'MessageCtrl@destroy')->where(['id' => '\\d+']); Route::put('/profile', ['middleware' => 'auth', function (Illuminate\Http\Request $request) { $firstname = $request->input('firstname'); $lastname = $request->input('lastname'); $profile = App\User::findOrFail(Auth::id()); $profile->firstname = $firstname; $profile->lastname = $lastname; $profile->save(); return ['changed' => true]; }]); Route::post('auth/login', 'Auth\\AuthController@postLogin'); Route::get('auth/isLogin', function () { if (Auth::check()) { $user = Auth::user(); return ['signed' => true, 'firstname' => $user->firstname, 'lastname' => $user->lastname]; } else { return ['signed' => false]; } }); Route::get('auth/logout', 'Auth\\AuthController@getLogout');