|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
|-------------------------------------------------------------------------- |
|
7
|
|
|
| API Routes |
|
8
|
|
|
|-------------------------------------------------------------------------- |
|
9
|
|
|
| |
|
10
|
|
|
| Here is where you can register API routes for your application. These |
|
11
|
|
|
| routes are loaded by the RouteServiceProvider within a group which |
|
12
|
|
|
| is assigned the "api" middleware group. Enjoy building your API! |
|
13
|
|
|
| |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
Route::middleware('auth:api')->get('/user', function (Request $request) { |
|
17
|
|
|
return $request->user(); |
|
18
|
|
|
}); |
|
19
|
|
|
|
|
20
|
|
|
Route::group(['namespace' => "Ergare17\Articles\Http\Controllers",'middleware' => 'api','prefix' => 'api/v1', 'middleware' => ['throttle','bindings']], function () { |
|
21
|
|
|
Route::group(['middleware' => 'auth:api'], function () { |
|
22
|
|
|
Route::get('/articles', 'APIArticlesController@index'); |
|
23
|
|
|
Route::get('/articles/{article}', 'APIArticlesController@show'); |
|
24
|
|
|
Route::post('/articles', 'APIArticlesController@store'); |
|
25
|
|
|
Route::put('/articles/{article}', 'APIArticlesController@update'); |
|
26
|
|
|
Route::delete('/articles/{article}', 'APIArticlesController@destroy'); |
|
27
|
|
|
|
|
28
|
|
|
Route::post('read-article/{article}', 'ApiReadArticleController@store'); |
|
29
|
|
|
Route::delete('read-article/{article}', 'ApiReadArticleController@destroy'); |
|
30
|
|
|
|
|
31
|
|
|
Route::put('description-article/{article}', 'ApiDescriptionArticleController@update'); |
|
32
|
|
|
|
|
33
|
|
|
Route::put('user_id-article/{article}', 'ApiUserIdArticleController@update'); |
|
34
|
|
|
|
|
35
|
|
|
Route::get('users', 'ApiUserController@index'); |
|
36
|
|
|
Route::get('users/{user}', 'ApiUserController@show'); |
|
37
|
|
|
Route::post('users', 'ApiUserController@store'); |
|
38
|
|
|
Route::put('users/{user}', 'ApiUserController@update'); |
|
39
|
|
|
Route::delete('users/{user}', 'ApiUserController@destroy'); |
|
40
|
|
|
}); |
|
41
|
|
|
}); |
|
42
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: