Browse Source
Use single SubscriptionFormRequest class to handle subscription CRUD
Use single SubscriptionFormRequest class to handle subscription CRUD
Add some helper method to subscription model Move subscription insert and update script from SubscriptionController to SubscriptionFormRequest class Move subscription delete view to edit view file Add breadcrumbs to subscription pagespull/1/head
18 changed files with 297 additions and 230 deletions
-
21app/Entities/Subscriptions/Subscription.php
-
48app/Http/Controllers/SubscriptionsController.php
-
117app/Http/Requests/SubscriptionRequest.php
-
39app/Http/Requests/Subscriptions/CreateRequest.php
-
31app/Http/Requests/Subscriptions/DeleteRequest.php
-
39app/Http/Requests/Subscriptions/UpdateRequest.php
-
4resources/lang/id/subscription.php
-
18resources/views/subscriptions/delete.blade.php
-
43resources/views/subscriptions/edit.blade.php
-
17resources/views/subscriptions/index.blade.php
-
5resources/views/subscriptions/partials/breadcrumb.blade.php
-
20resources/views/subscriptions/partials/delete.blade.php
-
43resources/views/subscriptions/partials/subscription-show.blade.php
-
15resources/views/subscriptions/show.blade.php
-
6routes/web.php
-
9routes/web/subscriptions.php
-
1tests/Feature/ManageSubscriptionsTest.php
-
49tests/Unit/Models/SubscriptionTest.php
@ -0,0 +1,117 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests; |
|||
|
|||
use App\Entities\Projects\Project; |
|||
use App\Entities\Subscriptions\Subscription; |
|||
use App\Http\Requests\Request; |
|||
|
|||
class SubscriptionRequest extends Request |
|||
{ |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return auth()->user()->can('manage_subscriptions'); |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
switch ($this->method()) { |
|||
case 'POST': |
|||
return $this->getCreateRules(); |
|||
break; |
|||
|
|||
case 'PATCH': |
|||
return $this->getUpdateRules(); |
|||
break; |
|||
|
|||
case 'DELETE': |
|||
return $this->getDeleteRules(); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
public function getCreateRules() |
|||
{ |
|||
return [ |
|||
'name' => 'required|max:60', |
|||
'price' => 'required|numeric', |
|||
'start_date' => 'required|date|date_format:Y-m-d', |
|||
'due_date' => 'required|date|date_format:Y-m-d', |
|||
'project_id' => 'required|numeric|exists:projects,id', |
|||
'vendor_id' => 'required|numeric|exists:vendors,id', |
|||
'type_id' => 'required|numeric', |
|||
'remark' => 'max:255', |
|||
]; |
|||
} |
|||
|
|||
public function getUpdateRules() |
|||
{ |
|||
return [ |
|||
'name' => 'required|max:60', |
|||
'price' => 'required|numeric', |
|||
'start_date' => 'required|date|date_format:Y-m-d', |
|||
'due_date' => 'required|date|date_format:Y-m-d', |
|||
'project_id' => 'required|numeric|exists:projects,id', |
|||
'vendor_id' => 'required|numeric|exists:vendors,id', |
|||
'type_id' => 'required|numeric', |
|||
'remark' => 'max:255', |
|||
]; |
|||
} |
|||
|
|||
public function getDeleteRules() |
|||
{ |
|||
// dd($this->route('subscription'));
|
|||
// dd($this->all(), $this->segment(2));
|
|||
return [ |
|||
'subscription_id' => 'required|in:'.$this->segment(2), |
|||
]; |
|||
} |
|||
|
|||
public function approveFor(Subscription $subscription) |
|||
{ |
|||
$project = Project::findOrFail($this->get('project_id')); |
|||
|
|||
if ($subscription->exists) { |
|||
$subscriptionData = $this->except(['_method', '_token']); |
|||
$subscriptionData['customer_id'] = $project->customer_id; |
|||
|
|||
$subscription->update($subscriptionData); |
|||
|
|||
} else { |
|||
|
|||
$subscription->project_id = $project->id; |
|||
$subscription->vendor_id = $this->get('vendor_id'); |
|||
$subscription->customer_id = $project->customer_id; |
|||
$subscription->name = $this->get('name'); |
|||
$subscription->price = $this->get('price'); |
|||
$subscription->start_date = $this->get('start_date'); |
|||
$subscription->due_date = $this->get('due_date'); |
|||
$subscription->type_id = $this->get('type_id'); |
|||
$subscription->notes = $this->get('notes'); |
|||
|
|||
$subscription->save(); |
|||
} |
|||
|
|||
return $subscription; |
|||
} |
|||
|
|||
public function approveToDelete(Subscription $subscription) |
|||
{ |
|||
$subscription->delete(); |
|||
} |
|||
|
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests\Subscriptions; |
|||
|
|||
use App\Http\Requests\Request; |
|||
|
|||
class CreateRequest extends Request |
|||
{ |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return auth()->user()->can('manage_subscriptions'); |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
'name' => 'required|max:60', |
|||
'price' => 'required|numeric', |
|||
'start_date' => 'required|date|date_format:Y-m-d', |
|||
'due_date' => 'required|date|date_format:Y-m-d', |
|||
'project_id' => 'required|numeric|exists:projects,id', |
|||
'vendor_id' => 'required|numeric|exists:vendors,id', |
|||
'type_id' => 'required|numeric', |
|||
'remark' => 'max:255', |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -1,31 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests\Subscriptions; |
|||
|
|||
use App\Http\Requests\Request; |
|||
|
|||
class DeleteRequest extends Request { |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return auth()->user()->can('manage_subscriptions'); |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
'subscription_id' => 'required' |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -1,39 +0,0 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Requests\Subscriptions; |
|||
|
|||
use App\Http\Requests\Request; |
|||
|
|||
class UpdateRequest extends Request |
|||
{ |
|||
|
|||
/** |
|||
* Determine if the user is authorized to make this request. |
|||
* |
|||
* @return bool |
|||
*/ |
|||
public function authorize() |
|||
{ |
|||
return auth()->user()->can('manage_subscriptions'); |
|||
} |
|||
|
|||
/** |
|||
* Get the validation rules that apply to the request. |
|||
* |
|||
* @return array |
|||
*/ |
|||
public function rules() |
|||
{ |
|||
return [ |
|||
'name' => 'required|max:60', |
|||
'price' => 'required|numeric', |
|||
'start_date' => 'required|date|date_format:Y-m-d', |
|||
'due_date' => 'required|date|date_format:Y-m-d', |
|||
'project_id' => 'required|numeric', |
|||
'vendor_id' => 'required|numeric', |
|||
'type_id' => 'required|numeric', |
|||
'remark' => 'max:255', |
|||
]; |
|||
} |
|||
|
|||
} |
|||
@ -1,18 +0,0 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.delete')) |
|||
|
|||
@section('content') |
|||
<h1 class="page-header"> |
|||
<div class="pull-right"> |
|||
{!! delete_button(['route'=>['subscriptions.destroy',$subscription->id]], trans('app.delete_confirm_button'), ['class'=>'btn btn-danger'], ['subscription_id'=>$subscription->id]) !!} |
|||
</div> |
|||
{{ trans('app.delete_confirm') }} |
|||
{!! link_to_route('subscriptions.show', trans('app.cancel'), [$subscription->id], ['class' => 'btn btn-default']) !!} |
|||
</h1> |
|||
<div class="row"> |
|||
<div class="col-md-4"> |
|||
@include('subscriptions.partials.subscription-show') |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -1,45 +1,56 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.edit')) |
|||
@section('title', $pageTitle) |
|||
|
|||
@section('content') |
|||
<div class="row"><br> |
|||
<div class="col-md-4"> |
|||
@include('subscriptions.partials.breadcrumb', ['title' => $pageTitle]) |
|||
|
|||
@includeWhen(request('action') == 'delete', 'subscriptions.partials.delete') |
|||
|
|||
@if (request('action') == null) |
|||
<div class="row"> |
|||
<div class="col-md-6 col-md-offset-3"> |
|||
{!! Form::model($subscription, ['route'=>['subscriptions.update', $subscription->id], 'method' => 'patch']) !!} |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ $subscription->domain_name }} <small>{{ trans('subscription.edit') }}</small></h3></div> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ $pageTitle }}</h3></div> |
|||
<div class="panel-body"> |
|||
<div class="row"> |
|||
<div class="col-md-6">{!! FormField::radios('type_id', $subscriptionTypes, ['label' => trans('subscription.type'), 'value' => Request::get('type_id')]) !!}</div> |
|||
<div class="col-md-6">{!! FormField::radios('status_id', [trans('app.in_active'), trans('app.active')],['label' => trans('app.status')]) !!}</div> |
|||
</div> |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('name',['label'=> trans('subscription.name')]) !!} |
|||
{!! FormField::text('name',['label' => trans('subscription.name')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::price('price',['label'=> trans('subscription.price')]) !!} |
|||
{!! FormField::price('price',['label' => trans('subscription.price')]) !!} |
|||
</div> |
|||
</div> |
|||
<div class="row"> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('start_date',['label'=> trans('subscription.start_date')]) !!} |
|||
{!! FormField::text('start_date',['label' => trans('subscription.start_date')]) !!} |
|||
</div> |
|||
<div class="col-sm-6"> |
|||
{!! FormField::text('due_date',['label'=> trans('subscription.due_date')]) !!} |
|||
{!! FormField::text('due_date',['label' => trans('subscription.due_date')]) !!} |
|||
</div> |
|||
</div> |
|||
{!! FormField::select('project_id', $projects,['label'=> trans('subscription.project')]) !!} |
|||
{!! FormField::select('vendor_id', $vendors,['label'=> trans('subscription.vendor')]) !!} |
|||
{!! FormField::radios('status_id', ['Non Active','Active'],['label'=> trans('app.status')]) !!} |
|||
{!! FormField::radios('type_id', $subscriptionTypes, ['label' => trans('subscription.type'), 'value' => Request::get('type_id')]) !!} |
|||
{!! FormField::textarea('notes',['label'=> trans('subscription.notes')]) !!} |
|||
{!! FormField::select('project_id', $projects,['label' => trans('subscription.project')]) !!} |
|||
{!! FormField::select('vendor_id', $vendors,['label' => trans('subscription.vendor')]) !!} |
|||
{!! FormField::textarea('notes',['label' => trans('subscription.notes')]) !!} |
|||
</div> |
|||
|
|||
<div class="panel-footer"> |
|||
{!! Form::submit(trans('subscription.update'), ['class'=>'btn btn-primary']) !!} |
|||
{!! link_to_route('subscriptions.show', trans('app.show'), [$subscription->id], ['class' => 'btn btn-info']) !!} |
|||
{!! link_to_route('subscriptions.index', trans('subscription.back_to_index'), [], ['class' => 'btn btn-default']) !!} |
|||
{!! link_to_route('subscriptions.delete', trans('subscription.delete'), [$subscription->id], ['class'=>'btn btn-danger pull-right']) !!} |
|||
</div> |
|||
</div> |
|||
{!! Form::close() !!} |
|||
</div> |
|||
<div class="col-md-3 text-center"> |
|||
<legend>@lang('app.action')</legend> |
|||
<p>{!! link_to_route('subscriptions.show', trans('subscription.show'), [$subscription->id], ['class' => 'btn btn-info']) !!}</p> |
|||
<p>{!! link_to_route('subscriptions.index', trans('subscription.back_to_index'), [], ['class' => 'btn btn-default']) !!}</p> |
|||
<p>{!! link_to_route('subscriptions.edit', trans('subscription.delete'), [$subscription->id, 'action' => 'delete'], ['class'=>'btn btn-danger']) !!}</p> |
|||
</div> |
|||
</div> |
|||
@endif |
|||
@endsection |
|||
@ -0,0 +1,5 @@ |
|||
<ul class="breadcrumb hidden-print"> |
|||
<li>{{ link_to_route('subscriptions.index',trans('subscription.list')) }}</li> |
|||
<li>{{ $subscription->nameLink() }}</li> |
|||
<li class="active">{{ isset($title) ? $title : trans('subscription.detail') }}</li> |
|||
</ul> |
|||
@ -0,0 +1,20 @@ |
|||
<div class="row"> |
|||
<div class="col-md-6 col-md-offset-3"> |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ trans('subscription.delete') }}</h3></div> |
|||
@include('subscriptions.partials.subscription-show') |
|||
<div class="panel-body"> |
|||
{{ trans('app.delete_confirm') }} |
|||
</div> |
|||
<div class="panel-footer"> |
|||
{!! link_to_route('subscriptions.edit', trans('app.cancel'), [$subscription->id], ['class' => 'btn btn-default']) !!} |
|||
{!! FormField::delete( |
|||
['route' => ['subscriptions.destroy', $subscription->id]], |
|||
trans('app.delete_confirm_button'), |
|||
['class' => 'btn btn-danger'], |
|||
['subscription_id' => $subscription->id] |
|||
) !!} |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@ -1,25 +1,18 @@ |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ trans('subscription.show') }}</h3></div> |
|||
<table class="table table-condensed"> |
|||
<tbody> |
|||
<tr><td>{{ trans('subscription.project') }}</td><td>{{ $subscription->project->name }}</td></tr> |
|||
<tr><td>{{ trans('subscription.name') }}</td><td>{{ $subscription->name }}</td></tr> |
|||
<tr><td>{{ trans('subscription.price') }}</td><td>{{ formatRp($subscription->price) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.type') }}</td><td>{{ $subscription->type }}</td></tr> |
|||
<tr><td>{{ trans('subscription.start_date') }}</td><td>{{ dateId($subscription->start_date) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.due_date') }}</td><td>{{ dateId($subscription->due_date) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.customer') }}</td><td>{{ $subscription->customer->name }}</td></tr> |
|||
<tr> |
|||
<td>{{ trans('subscription.project') }}</td> |
|||
<td> |
|||
{{ link_to_route('projects.subscriptions', $subscription->project->name, [$subscription->project_id], ['target' => '_blank']) }} |
|||
</td> |
|||
</tr> |
|||
<tr><td>{{ trans('subscription.notes') }}</td><td>{!! nl2br($subscription->notes) !!}</td></tr> |
|||
</tbody> |
|||
</table> |
|||
<div class="panel-footer"> |
|||
{!! link_to_route('subscriptions.edit', trans('subscription.edit'), [$subscription->id], ['class' => 'btn btn-warning']) !!} |
|||
{!! link_to_route('subscriptions.index', trans('subscription.back_to_index'), [], ['class' => 'btn btn-default']) !!} |
|||
</div> |
|||
</div> |
|||
<table class="table table-condensed"> |
|||
<tbody> |
|||
<tr><td>{{ trans('subscription.project') }}</td><td>{{ $subscription->project->name }}</td></tr> |
|||
<tr><td>{{ trans('subscription.name') }}</td><td>{{ $subscription->name }}</td></tr> |
|||
<tr><td>{{ trans('subscription.price') }}</td><td>{{ formatRp($subscription->price) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.type') }}</td><td>{{ $subscription->type }}</td></tr> |
|||
<tr><td>{{ trans('subscription.start_date') }}</td><td>{{ dateId($subscription->start_date) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.due_date') }}</td><td>{{ dateId($subscription->due_date) }}</td></tr> |
|||
<tr><td>{{ trans('subscription.customer') }}</td><td>{{ $subscription->customer->name }}</td></tr> |
|||
<tr> |
|||
<td>{{ trans('subscription.project') }}</td> |
|||
<td> |
|||
{{ link_to_route('projects.subscriptions', $subscription->project->name, [$subscription->project_id], ['target' => '_blank']) }} |
|||
</td> |
|||
</tr> |
|||
<tr><td>{{ trans('subscription.notes') }}</td><td>{!! nl2br($subscription->notes) !!}</td></tr> |
|||
</tbody> |
|||
</table> |
|||
@ -1,12 +1,21 @@ |
|||
@extends('layouts.app') |
|||
|
|||
@section('title', trans('subscription.show')) |
|||
@section('title', trans('subscription.detail')) |
|||
|
|||
@section('content') |
|||
<h1 class="page-header">{{ $subscription->domain_name }} <small>{{ trans('subscription.show') }}</small></h1> |
|||
@include('subscriptions.partials.breadcrumb') |
|||
|
|||
<h1 class="page-header">{{ $subscription->name }} <small>{{ trans('subscription.detail') }}</small></h1> |
|||
<div class="row"> |
|||
<div class="col-md-6"> |
|||
@include('subscriptions.partials.subscription-show') |
|||
<div class="panel panel-default"> |
|||
<div class="panel-heading"><h3 class="panel-title">{{ trans('subscription.detail') }}</h3></div> |
|||
@include('subscriptions.partials.subscription-show') |
|||
<div class="panel-footer"> |
|||
{!! link_to_route('subscriptions.edit', trans('subscription.edit'), [$subscription->id], ['class' => 'btn btn-warning']) !!} |
|||
{!! link_to_route('subscriptions.index', trans('subscription.back_to_index'), [], ['class' => 'btn btn-default']) !!} |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
@endsection |
|||
@ -1,9 +0,0 @@ |
|||
<?php |
|||
|
|||
Route::group(['middleware' => ['web', 'auth']], function () { |
|||
/** |
|||
* Subscriptions Routes |
|||
*/ |
|||
Route::get('subscriptions/{subscription}/delete', ['as' => 'subscriptions.delete', 'uses' => 'SubscriptionsController@delete']); |
|||
Route::resource('subscriptions', 'SubscriptionsController'); |
|||
}); |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue