Skip to content

Instantly share code, notes, and snippets.

@evercode1
Created February 10, 2017 22:47
Show Gist options
  • Select an option

  • Save evercode1/b07409935ecf198ea40cf7f8eb54046f to your computer and use it in GitHub Desktop.

Select an option

Save evercode1/b07409935ecf198ea40cf7f8eb54046f to your computer and use it in GitHub Desktop.
ValidationServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Subcategory;
class ValidatorServiceProvider extends ServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
$this->app['validator']->extend('belongsToCategory', function ($attribute, $value, $parameters)
{
$category_id = request()->input('category_id');
$verified = Subcategory::where('id', $value)
->where('category_id', $category_id)
->exists();
return 'belongsToCategory' == $verified;
},
'Sorry, subcategory does not belong to category!');
}
/**
* Register the application services.
*
* @return void
*/
public function register()
{
//
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment