Laravel Backpack Portfolio Package
This package provides a portfolio for my laravel based blog. It requires Backpack for Laravel so you will need to install it.
Installation
This package is available through packagist. Install it with the following command.
composer require tjventurini/portfolio
Migrations
You will need to run the migrations for the portfolios table.
php artisan migrate
Config
You will need to publish the package configuraton.
php artisan vendor:publish --provider="Tjventurini\Portfolio\PortfolioServiceProvider" --tag=config
Views (optional)
The views are available through portfolio::view-name
even though you don't publish them.
php artisan vendor:publish --provider="Tjventurini\Portfolio\PortfolioServiceProvider" --tag=views
Translations (optional)
The translations are available through portfolio::portfolio.key
even though you don't publish them.
php artisan vendor:publish --provider="Tjventurini\Portfolio\PortfolioServiceProvider" --tag=lang
Seeding (optional)
The package provides seeding for the tags table.
artisan db:seed --class="Tjventurini\Portfolio\Database\Seeds\PortfolioSeeder"
Backpack
By now you should be ready to update the backpack admin panel. Open resources/views/vendor/backpack/base/inc/sidebar_content.blade.php
and add the following line.
<li><a href="{{ backpack_url('portfolio') }}"><i class="fa fa-files-o"></i> <span>{{ trans('portfolio::portfolio.menu_item') }}</span></a></li>
Portfolio makes use of tjventurini/tags package for tagging. To use it in backpack admin panel you also need to add the following line to sidebar_content.blade.php
. Visit the tjventurini/tags repository for more information about tags.
<li><a href="{{ backpack_url('tag') }}"><i class="fa fa-tag"></i> <span>{{ trans('tags::tags.menu_item') }}</span></a></li>
The last thing to do is to publish the buttons needed for the backpack crud.
php artisan vendor:publish --provider="Tjventurini\Portfolio\PortfolioServiceProvider" --tag=backpack
Configuration
Routes
/*
|--------------------------------------------------------------------------
| Tjventurini\Portfolio Routes
|--------------------------------------------------------------------------
|
| In this file you will find all routes needed for this package to work in
| in the backpack backend as well as the frontend.
|
*/
Route::group([
'prefix' => config('backpack.base.route_prefix', 'admin'),
'middleware' => ['web', config('backpack.base.middleware_key', 'admin')],
'namespace' => 'Tjventurini\Portfolio\App\Http\Controllers\Admin',
], function () {
CRUD::resource('portfolio', 'PortfolioCrudController');
});
Route::group([
'prefix' => 'portfolio',
'middleware' => ['web'],
'namespace' => 'Tjventurini\Portfolio\App\Http\Controllers',
], function () {
// show portfolios
Route::get('/', 'PortfolioController@index')->name('portfolio');
// show portfolio
Route::get('/{slug}', 'PortfolioController@portfolio')->name('portfolio.portfolio');
});
Route Prefix
/*
|--------------------------------------------------------------------------
| Route Prefix
|--------------------------------------------------------------------------
|
| In this section you can define the route prefix of this package.
|
*/
'route_prefix' => 'portfolio',
Views
/*
|--------------------------------------------------------------------------
| Views
|--------------------------------------------------------------------------
|
| In this section you can define the views to show when the routes are
| called.
|
*/
// view to show all portfolios
'view_portfolios' => 'portfolio::portfolios',
// view to show single portfolio
'view_portfolio' => 'portfolio::portfolio',
Validation
/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
|
| In this section you can change the validation rules for the tags request.
|
*/
'rules' => [
'name' => 'required|min:5|max:255',
'slug' => 'unique:portfolios,slug',
'type' => 'required|in:fa-desktop,fa-image,fa-mobile',
'image' => 'required|string',
'tags' => 'required',
],
Portfolio Types
Portfolio types are defined in two places, the configuration and the translations. You can define the types any way you want or clear the array completely, but always remember to update the validation to.
/*
|--------------------------------------------------------------------------
| Portfolio Types
|--------------------------------------------------------------------------
|
| In this section you can define the portfolio pypes you have.
|
*/
'types' => [
// icon => label
'fa-desktop' => 'Website',
'fa-image' => 'Picture',
'fa-mobile' => 'App',
],
Date Format
/*
|--------------------------------------------------------------------------
| Date Format
|--------------------------------------------------------------------------
|
| In this section you can define the date format used for portfolios.
|
*/
'date_format' => 'd.m.Y',