The purpose of this repository is to show good development practices on Laravel as well as to present cases of use of the framework's features like:
- Authentication
- API
- Token authentication
- API Resources
- Versioning
- Blade
- Broadcasting
- Cache
- Email Verification
- Filesystem
- Helpers
- Horizon
- Localization
- Migrations
- Policies
- Providers
- Requests
- Seeding & Factories
- Testing
- Homestead
Beside Laravel, this project uses other tools like:
- Bootstrap 4
- PHP-CS-Fixer
- Travis CI
- Font Awesome
- Vue.js
- axios
- Redis
- spatie/laravel-medialibrary
- Many more to discover.
You can find some screenshots of the application on : https://imgur.com/a/Jbnwj
Development environment requirements :
Setting up your development environment on your local machine :
$ git clone https://github.com/guillaumebriday/laravel-blog.git
$ cd laravel-blog
$ cp .env.example .env
$ composer install
$ vagrant up
$ vagrant ssh
All following commands must be run inside the VM:
$ cd code???
$ yarn install
$ php artisan key:generate
$ php artisan horizon:install
$ php artisan telescope:install
$ php artisan storage:link
Now you can access the application via http://localhost:8000.
There is no need to run php artisan serve
. PHP is already running in the dedicated virtual machine.
first verify that extension url in php.ini set and configure correctly:
extension_dir = "ext"
uncomment:
- curl
- fileinfo
- gd
- mbstring
- exif
- zip
- mysqli
- openssl extension=intl
add this:
- php_pdo_mysql.dll
extension=gd
extension=mbstring
extension=exif
- create db
- composer i
- composer u
- env file. those key in .env.example that comment
- php artisan migrate
- php artisan storage:link
- php artisan queue:work
- php artisan schedule:run
- php artisan serve
- create user
- register user and check email to activate user by mailtrap
- make this user admin by role-user table add role id 2
- goto dashboard
- upload image
- create post with this image
cd /home/pardisa2/bots && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1 cd /home/pardisa2/blog && /usr/local/bin/php artisan queue:work >> /dev/null 2>&1
You need to run the migrations with the seeds :
$ php artisan migrate --seed
This will create a new user that you can use to sign in :
email: darthvader@deathstar.ds
password: 4nak1n
And then, compile the assets :
$ yarn dev # or yarn watch
Starting job for newsletter :
$ php artisan tinker
> PrepareNewsletterSubscriptionEmail::dispatch();
Seeding the database :
$ php artisan db:seed
Running tests :
$ ./vendor/bin/phpunit --cache-result --order-by=defects --stop-on-defect
Running php-cs-fixer :
$ ./vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --dry-run --diff
Generating backup :
$ php artisan vendor:publish --provider="Spatie\Backup\BackupServiceProvider"
$ php artisan backup:run
Generating fake data :
$ php artisan db:seed --class=DevDatabaseSeeder
Discover package
$ php artisan package:discover
In development environnement, rebuild the database :
$ php artisan migrate:fresh --seed
Clients can access to the REST API. API requests require authentication via token. You can create a new token in your user profile.
Then, you can use this token either as url parameter or in Authorization header :
# Url parameter
GET http://laravel-blog.app/api/v1/posts?api_token=your_private_token_here
# Authorization Header
curl --header "Authorization: Bearer your_private_token_here" http://laravel-blog.app/api/v1/posts
API are prefixed by api
and the API version number like so v1
.
Do not forget to set the X-Requested-With
header to XMLHttpRequest
. Otherwise, Laravel won't recognize the call as an AJAX request.
To list all the available routes for API :
$ php artisan route:list --path=api
Do not hesitate to contribute to the project by adapting or adding features ! Bug reports or pull requests are welcome.
This project is released under the MIT license.