Skip to content

Commit 571e5c8

Browse files
committed
implementing moduler structure
1 parent d366822 commit 571e5c8

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

app/Providers/RouteServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ protected function mapWebRoutes()
6565
*/
6666
protected function mapApiRoutes()
6767
{
68-
Route::prefix('api/v1')
68+
Route::prefix('api')
6969
->middleware('api')
7070
->namespace($this->namespace . '\\Api')
7171
->group(base_path('routes/api.php'));

config/api.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return [
4+
// api version
5+
'api_version' => env('API_VERSION', 'v1'),
6+
7+
// personal client
8+
'personal_client_id' => env('PERSONAL_CLIENT_ID', 1),
9+
'personal_client_key' => env('PERSONAL_CLIENT_SECRET', ''),
10+
11+
// password client
12+
'password_client_id' => env('PASSWORD_CLIENT_ID', 2),
13+
'password_client_secret' => env('PASSWORD_CLIENT_SECRET', ''),
14+
];

routes/api.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?php
22

33
use Illuminate\Support\Facades\Route;
4-
use Illuminate\Http\Request;
5-
use App\User;
6-
use App\Article;
74

85
/*
96
|--------------------------------------------------------------------------
@@ -18,7 +15,21 @@
1815

1916
// default name space for all routes is 'App\Http\Controllers\Api'
2017

21-
Route::post('auth/register', 'Auth\RegisterController@register')->name('auth.register');
18+
$api_version = config('api.api_version');
19+
20+
Route::group(["prefix" => "{$api_version}"], function() {
21+
// register auth routes
22+
Route::prefix('auth')
23+
->group(base_path('routes/api/auth.php'));
24+
// register users routes
25+
Route::prefix('users')
26+
->group(base_path('routes/api/users.php'));
27+
// register articles routes
28+
Route::prefix('articles')
29+
->group(base_path('routes/api/articles.php'));
30+
});
31+
32+
/*Route::post('auth/register', 'Auth\RegisterController@register')->name('auth.register');
2233
Route::post('auth/login', 'Auth\LoginController@login')->name('auth.login');
2334
Route::get('articles/published', 'ArticleController@publishedArticles')->name('articles.published.index');
2435
Route::get('articles/published/{id}', 'ArticleController@publishedArticle')->name('articles.published.show');
@@ -33,4 +44,4 @@
3344
Route::resource('articles', 'ArticleController', ['except' => ['edit', 'create']]);
3445
3546
Route::delete('/auth/logout', 'Auth\LoginController@logout')->name('auth.logout');;
36-
});
47+
});*/

routes/api/articles.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
Route::get('published', 'ArticleController@publishedArticles')->name('articles.published.index');
6+
Route::get('published/{id}', 'ArticleController@publishedArticle')->name('articles.published.show');
7+
8+
Route::group(['middleware' => 'auth:api'], function() {
9+
Route::apiResource('/', 'ArticleController');
10+
});

routes/api/auth.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
use Illuminate\Http\Request;
4+
use Illuminate\Support\Facades\Route;
5+
6+
Route::post('register', 'Auth\RegisterController@register')->name('auth.register');
7+
Route::post('login', 'Auth\LoginController@login')->name('auth.login');
8+
9+
Route::group(['middleware' => 'auth:api'], function() {
10+
Route::delete('/logout', 'Auth\LoginController@logout')->name('auth.logout');;
11+
12+
Route::get('/user', function (Request $request) {
13+
return $request->user();
14+
});
15+
});

routes/api/users.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Route;
4+
5+
Route::group(['middleware' => 'auth:api'], function() {
6+
Route::patch('/{id}', 'UserController@update')->name('users.update');
7+
});

0 commit comments

Comments
 (0)