Skip to content

Instantly share code, notes, and snippets.

@eightyfive
Last active November 22, 2020 22:43
Show Gist options
  • Save eightyfive/b4e3c319f8616fe08a79e28666efada7 to your computer and use it in GitHub Desktop.
Save eightyfive/b4e3c319f8616fe08a79e28666efada7 to your computer and use it in GitHub Desktop.
Laravel 8 app boilerplate
@@ -7,9 +7,9 @@
LOG_CHANNEL=stack
LOG_LEVEL=debug
-DB_CONNECTION=mysql
+DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
-DB_PORT=3306
+DB_PORT=5432
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class SessionController extends Controller
{
public function user(Request $request)
{
return $request->user();
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class IndexController extends Controller
{
public function index(Request $request)
{
return view('index');
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class SessionController extends Controller
{
public function user(Request $request)
{
$user = $request->user();
return response()->json($user ?? "");
}
}
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Support\Str;
abstract class EloquentRepository
{
protected $model;
public function __construct(Eloquent $model)
{
$this->model = $model;
}
protected function query()
{
return $this->model->newQuery();
}
protected function queryMany()
{
return $this->query();
}
public function __call($method, $args)
{
$matches = [];
preg_match('/(find|get)By(\w+)/', $method, $matches);
$matched = count($matches) > 0;
if ($matched) {
$isMany = $matches[1] === 'get';
$name = Str::snake($matches[2]);
$value = array_shift($args);
$query = $isMany ? $this->queryMany() : $this->query();
// Where
if (is_array($value)) {
$query->whereIn($name, $value);
} else {
$query->where($name, $value);
}
// Order by
if (count($args)) {
$name = array_shift($args);
$dir = array_shift($args) ?? 'asc';
$query->orderBy($name, $dir);
}
return $isMany ? $query->get() : $query->first();
}
}
}
<?php
namespace App\Models;
trait Routable
{
public function getRouteKeyName()
{
return 'slug';
}
public function resolveRouteBinding($value, $field = null)
{
if (is_numeric($value)) {
$query = $this->where($this->getKeyName(), $value);
} else {
$query = $this->where($this->getRouteKeyName(), $value);
}
return $query->firstOrFail();
}
}
@@ -7,48 +7,22 @@
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
+// use Eyf\Autoroute\Autoroute;
class RouteServiceProvider extends ServiceProvider
{
- /**
- * The path to the "home" route for your application.
- *
- * This is used by Laravel authentication to redirect users after login.
- *
- * @var string
- */
- public const HOME = '/home';
-
- /**
- * The controller namespace for the application.
- *
- * When present, controller route declarations will automatically be prefixed with this namespace.
- *
- * @var string|null
- */
- // protected $namespace = 'App\\Http\\Controllers';
+ public const HOME = '/';
- /**
- * Define your route model bindings, pattern filters, etc.
- *
- * @return void
- */
public function boot()
{
$this->configureRateLimiting();
-
- $this->routes(function () {
- Route::prefix('api')
- ->middleware('api')
- ->namespace($this->namespace)
- ->group(base_path('routes/api.php'));
-
- Route::middleware('web')
- ->namespace($this->namespace)
- ->group(base_path('routes/web.php'));
- });
}
+ // public function map(Autoroute $autoroute)
+ // {
+ // $autoroute->load(['api.yaml', 'web.yaml']);
+ // }
+
/**
* Configure the rate limiters for the application.
*
<?php
namespace App\Services;
use GuzzleHttp\Client as Http;
abstract class Api
{
protected $http;
public function __construct(Http $http)
{
$this->http = $http;
}
protected function get($path, array $params = [])
{
return $this->request('GET', $path, [
'query' => $params,
]);
}
protected function post($path, array $params)
{
return $this->request('POST', $path, [
'json' => $params,
]);
}
protected function put($path, array $params)
{
return $this->request('PUT', $path, [
'json' => $params,
]);
}
protected function delete($path, array $params)
{
return $this->request('DELETE', $path, [
'json' => $params,
]);
}
protected function request(string $method, string $path, array $options)
{
$res = $this->http->request($method, $path, $options);
return json_decode($res->getBody(), true);
}
}
@@ -9,6 +9,7 @@
"license": "MIT",
"require": {
"php": "^7.3|^8.0",
+ "eyf/laravel-autoroute": "^1.0",
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
@@ -16,6 +17,7 @@
"laravel/tinker": "^2.5"
},
"require-dev": {
+ "eyf/laravel-exodus": "dev-master",
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"mockery/mockery": "^1.4.2",
[prod]
user <USER>
host 178.128.63.234
repo git@bitbucket.org:<USERNAME>/<APP_NAME>.git
path /home/<USER>/var/www/<APP_NAME>
ref origin/master
post-deploy ./scripts/deploy-post.sh
@@ -10,10 +10,17 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --config=node_modules/laravel-mix/setup/webpack.config.js"
},
"devDependencies": {
- "axios": "^0.19",
+ "@babel/preset-react": "^7.12.5",
+ "@prettier/plugin-php": "^0.14.3",
+ "bulma": "^0.9.1",
"cross-env": "^7.0",
"laravel-mix": "^5.0.1",
- "lodash": "^4.17.19",
- "resolve-url-loader": "^3.1.0"
+ "prettier": "^2.1.1",
+ "react": "^17.0.1",
+ "react-dom": "^17.0.1",
+ "resolve-url-loader": "^3.1.0",
+ "sass": "^1.15.2",
+ "sass-loader": "^8.0.0",
+ "vue-template-compiler": "^2.6.12"
}
}
@@ -1 +1 @@
-require('./bootstrap');
+//
@extends('layout')
@section('title')
Home
@endsection
@section('content')
<x-container>
<x-header title="Home" />
<div class="content">
<p>Lorem ipsum.</p>
</div>
<div class="buttons">
<x-button primary>Button</x-button>
<x-button>Button</x-button>
</div>
</x-container>
@endsection
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@yield('title') | {{ env('APP_NAME') }}</title>
<link rel="preload" href="{{ mix('/css/app.css') }}" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript><link rel="stylesheet" href="{{ mix('/css/app.css') }}"></noscript>
<script src="{{ mix('/js/app.js') }}" defer></script>
@yield('head')
</head>
<body>
@section('header')
<nav class="navbar is-primary" role="navigation" aria-label="main navigation">
<x-container>
<div class="navbar-brand">
<a class="navbar-item" href="/">
&#129304;
{{ env('APP_NAME') }}
</a>
<a role="button" id="navbarBurger" class="navbar-burger burger" aria-label="menu" aria-expanded="false">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarMenu" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" href="/">
Home
</a>
</div>
<div id="menuApp" class="navbar-end">
</div>
</div>
</x-container>
</nav>
@show
<main id="main">
@if($errors->any())
<x-notification danger light>
Please review form
</x-notification>
@elseif(session('notification'))
<x-notification info light>
{{ session('notification') }}
</x-notification>
@endif
@yield('content')
</main>
@section('footer')
<footer class="footer">
<p>
<small>All rights reserved &#129304; {{ env('APP_NAME') }} 2020 &copy;</small>
</p>
<p>
<a href="https://bulma.io">
<img src="https://bulma.io/images/made-with-bulma--black.png" alt="Made with Bulma" width="128" height="24">
</a>
</p>
</footer>
@show
@section('javascripts')
<script>
const initialState = {
csrf: "{{ csrf_token() }}"
};
</script>
@show
</body>
</html>
group:
prefix: api
middleware:
- api
namespace: App\Http\Controllers\Api
paths:
group:
middleware:
- auth:api
paths:
"user":
get: session.user
group:
middleware:
- web
namespace: App\Http\Controllers
paths:
"/":
get: index.index
"/user":
get: session.user
#!/bin/bash
ln -nfs $SHARED/.env .
ln -nfs $SHARED/storage .
composer install --no-dev --optimize-autoloader
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan optimize
#!/bin/bash
# ¡ Need to run from project root !
mkdir ./shared/storage
mkdir ./shared/storage/app
mkdir ./shared/storage/app/public
mkdir ./shared/storage/framework
mkdir ./shared/storage/framework/cache
mkdir ./shared/storage/framework/cache/data
mkdir ./shared/storage/framework/sessions
mkdir ./shared/storage/framework/testing
mkdir ./shared/storage/framework/views
mkdir ./shared/storage/logs
chgrp -R www-data ./shared/storage
chmod -R g+rwxs ./shared/storage
@@ -1,17 +1,10 @@
-const mix = require('laravel-mix');
+const mix = require("laravel-mix");
-/*
- |--------------------------------------------------------------------------
- | Mix Asset Management
- |--------------------------------------------------------------------------
- |
- | Mix provides a clean, fluent API for defining some Webpack build steps
- | for your Laravel applications. By default, we are compiling the CSS
- | file for the application as well as bundling up all the JS files.
- |
- */
+mix.react("resources/js/app.js", "public/js").sass(
+ "resources/sass/app.scss",
+ "public/css"
+);
-mix.js('resources/js/app.js', 'public/js')
- .postCss('resources/css/app.css', 'public/css', [
- //
- ]);
+if (mix.inProduction()) {
+ mix.version();
+}
{
"keywords": ["laravel"],
"bundled": ["ca8b51e2f06e47e25143e914a0817275", "b0ae559ac0557ddbaf955ebebbb76325"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment