Wallogit.com
2017 © Pedro Peláez
laravel blog app
A simple Blog Module for Laravel 5, (*1)
Create a file called module.php inside the config directory.
Add following code in module.php., (*2)
```` return [ 'modules' => [ 'Blog', ] ]; ```, (*3)
You can add more then one modules inside modules array., (*4)
Open up the file config/app.php and add 'App\Modules\ModulesServiceProvider', to the end of the providers array., (*5)
'providers' => [
App\Modules\ModulesServiceProvider::class,
]
Create new folder called Modules inside app directory., (*6)
Add Blog folder inside Modules directory. App directory structure look like this:, (*7)
app/
|---Modules
|---Blog
|---Assets
|---Components
|---Controllers
|---Middleware
|---Migrations
|---Models
|---Views
|---BlogServiceProvider.php
|---routes.php
|---ModulesServiceProvider.php
Head to the Modules directory and add a file called ModulesServiceProvider.php, (*8)
Run Migrations. For that use following command., (*9)
$ php artisan migrate --path app/Modules/Blog/Migrations
(Role column will be added into your users table. That will be define which user has author/admin role. You can change table name as per your requirement.), (*10)
Add following methods into app/User.php, (*11)
/**
* user has many posts
* @return type
*/
public function posts()
{
return $this->hasMany('App\Modules\Blog\Models\Posts', 'author_id');
}
/**
* user has many comments
* @return type
*/
public function comments()
{
return $this->hasMany('App\Modules\Blog\Models\Comments', 'from_user');
}
/**
* Check if user can post blog
* @return boolean
*/
public function can_post()
{
$role = $this->role;
if ($role == 'author' || $role == 'admin') {
return true;
}
return false;
}
/**
* Check if user is admin
* @return boolean
*/
public function is_admin()
{
$role = $this->role;
if ($role == 'admin') {
return true;
}
return false;
}
To set facebook API key open up Blog/Views/layouts/app.blade.php and set, (*12)
appId : 'your app id',
in line number 8., (*13)
To get twitter count register your domain on any APIs which providers twitter count. Open up Blog/Views/posts/show.blade.php and set Provided path to, (*14)
data-via : 'Your domain path'
in line number 187., (*15)
For Routes you can add/update in Blog/routes.php (Blog module has its own routes.php so you can add/update routes here.), (*16)
Please run composer dump-autoload, if you come across any Class not found exceptions and you haven’t done anything wrong, (*17)
This module is tested in fresh copy of laravel 5. If you have customised your application then please change as per your application., (*18)
http://plugins.auratechmind.net/laravel-blog/public/, (*19)
http://auratechmind.net/question/category/laravel-blog/, (*20)
https://opensharecount.com/, (*21)
https://developers.facebook.com/, (*22)
http://www.findalltogether.com/tutorial/simple-blog-application-in-laravel-5/, (*23)