Skip to content

Commit 48c5539

Browse files
committed
psr4 autoload, route service and custom resource view
1 parent 72ea03c commit 48c5539

File tree

8 files changed

+215
-1
lines changed

8 files changed

+215
-1
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@ $ docker ps
2323
$ docker-machine ip
2424
```
2525
All data and logs will be stored in `data` and `logs` root directories. Source projects in `src` root directory.
26+
27+
## Laravel project
28+
29+
* psr-4 autoload
30+
* RouteService Provider
31+
* Custom resource view

src/laravel/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"database"
2121
],
2222
"psr-4": {
23-
"App\\": "app/"
23+
"App\\": "app/",
24+
"": "src/"
2425
}
2526
},
2627
"autoload-dev": {

src/laravel/config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
// App\Providers\BroadcastServiceProvider::class,
178178
App\Providers\EventServiceProvider::class,
179179
App\Providers\RouteServiceProvider::class,
180+
Fmgonzalez\Providers\RouteService::class,
180181

181182
],
182183

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Fmgonzalez\Controllers;
4+
use Illuminate\Routing\Controller as BaseController;
5+
6+
class Task extends BaseController {
7+
8+
public function index() {
9+
$defaultMessage = 'Tasks page';
10+
return view('fmgonzalez::home')->withMessage($defaultMessage);
11+
}
12+
13+
public function show($id) {
14+
$defaultMessage = "Task $id page";
15+
return view('fmgonzalez::home')->withMessage($defaultMessage);
16+
}
17+
18+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Fmgonzalez\Providers;
4+
5+
use \Illuminate\Support\Facades\Route;
6+
use \Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7+
8+
class RouteService extends ServiceProvider
9+
{
10+
/**
11+
* This namespace is applied to your controller routes.
12+
*
13+
* In addition, it is set as the URL generator's root namespace.
14+
*
15+
* @var string
16+
*/
17+
protected $namespace = 'Fmgonzalez\Controllers';
18+
19+
/**
20+
* Define your route model bindings, pattern filters, etc.
21+
*
22+
* @return void
23+
*/
24+
public function boot()
25+
{
26+
parent::boot();
27+
$this->loadViewsFrom(realpath(__DIR__.'/../resources/views'), 'fmgonzalez');
28+
}
29+
30+
/**
31+
* Define the routes for the application.
32+
*
33+
* @return void
34+
*/
35+
public function map()
36+
{
37+
$this->mapApiRoutes();
38+
$this->mapWebRoutes();
39+
}
40+
41+
/**
42+
* Define the "api" routes for the application.
43+
*
44+
* These routes all receive session state, CSRF protection, etc.
45+
*
46+
* @return void
47+
*/
48+
protected function mapApiRoutes()
49+
{
50+
Route::group([
51+
'middleware' => 'api',
52+
'namespace' => $this->namespace,
53+
], function ($router) {
54+
require realpath(__DIR__.'/../routes/api.php');
55+
});
56+
}
57+
58+
/**
59+
* Define the "web" routes for the application.
60+
*
61+
* These routes all receive session state, CSRF protection, etc.
62+
*
63+
* @return void
64+
*/
65+
protected function mapWebRoutes()
66+
{
67+
Route::group([
68+
'middleware' => 'web',
69+
'namespace' => $this->namespace,
70+
], function ($router) {
71+
require realpath(__DIR__.'/../routes/web.php');
72+
});
73+
}
74+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
8+
<title>Laravel</title>
9+
10+
<!-- Fonts -->
11+
<link href="https://fonts.googleapis.com/css?family=Raleway:100,600" rel="stylesheet" type="text/css">
12+
13+
<!-- Styles -->
14+
<style>
15+
html, body {
16+
background-color: #fff;
17+
color: #636b6f;
18+
font-family: 'Raleway', sans-serif;
19+
font-weight: 100;
20+
height: 100vh;
21+
margin: 0;
22+
}
23+
24+
.full-height {
25+
height: 100vh;
26+
}
27+
28+
.flex-center {
29+
align-items: center;
30+
display: flex;
31+
justify-content: center;
32+
}
33+
34+
.position-ref {
35+
position: relative;
36+
}
37+
38+
.top-right {
39+
position: absolute;
40+
right: 10px;
41+
top: 18px;
42+
}
43+
44+
.content {
45+
text-align: center;
46+
}
47+
48+
.title {
49+
font-size: 84px;
50+
}
51+
52+
.links > a {
53+
color: #636b6f;
54+
padding: 0 25px;
55+
font-size: 12px;
56+
font-weight: 600;
57+
letter-spacing: .1rem;
58+
text-decoration: none;
59+
text-transform: uppercase;
60+
}
61+
62+
.m-b-md {
63+
margin-bottom: 30px;
64+
}
65+
</style>
66+
</head>
67+
<body>
68+
<div class="flex-center position-ref full-height">
69+
@if (Route::has('login'))
70+
<div class="top-right links">
71+
@if (Auth::check())
72+
<a href="{{ url('/home') }}">Home</a>
73+
@else
74+
<a href="{{ url('/login') }}">Login</a>
75+
<a href="{{ url('/register') }}">Register</a>
76+
@endif
77+
</div>
78+
@endif
79+
80+
<div class="content">
81+
<div class="title m-b-md">
82+
{{ $message }}
83+
</div>
84+
</div>
85+
</div>
86+
</body>
87+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Web Routes
6+
|--------------------------------------------------------------------------
7+
|
8+
| This file is where you may define all of the routes that are handled
9+
| by your application. Just tell Laravel the URIs it should respond
10+
| to using a Closure or controller method. Build something great!
11+
|
12+
*/
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Web Routes
6+
|--------------------------------------------------------------------------
7+
|
8+
| This file is where you may define all of the routes that are handled
9+
| by your application. Just tell Laravel the URIs it should respond
10+
| to using a Closure or controller method. Build something great!
11+
|
12+
*/
13+
14+
Route::get('/tasks', 'Task@index');
15+
Route::get('/tasks/{id}', 'Task@show');

0 commit comments

Comments
 (0)