Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/Commands/RepositoryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class RepositoryCommand extends GeneratorCommand
* Execute the console command.
*
* @return bool|null
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function handle()
{
Expand All @@ -47,6 +48,7 @@ public function handle()
*
* @param string $name
* @return string
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
protected function buildClass($name)
{
Expand All @@ -60,6 +62,19 @@ protected function buildClass($name)
$model = $this->laravel->getNamespace().$model;
}

if ($this->option('all')) {
$this->call('make:model', [
'name' => $this->argument('name'),
'--factory' => true,
'--migration' => true,
'--controller' => true,
]);

$this->call('make:policy', [
'name' => $this->argument('name').'Policy',
]);
}

return str_replace(
'DummyFullModel', $model, parent::buildClass($name)
);
Expand Down Expand Up @@ -94,6 +109,7 @@ protected function getDefaultNamespace($rootNamespace)
protected function getOptions()
{
return [
['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, factory, and controller for the repository'],
['model', 'm', InputOption::VALUE_REQUIRED, 'The model class being represented.'],
];
}
Expand Down
93 changes: 93 additions & 0 deletions src/Commands/stubs/policy.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Policies;

use App\User;
use Illuminate\Auth\Access\HandlesAuthorization;

class DummyClass
{
use HandlesAuthorization;

/**
* Determine whether the user can view any models.
*
* @param \App\User $user
* @return mixed
*/
public function viewAny(User $user = null)
{
return true;
}

/**
* Determine whether the user can view the model.
*
* @param \App\User $user
* @param \App\User $model
* @return mixed
*/
public function view(User $user = null, User $model = null)
{
return true;
}

/**
* Determine whether the user can create models.
*
* @param \App\User $user
* @return mixed
*/
public function create(User $user = null)
{
return true;
}

/**
* Determine whether the user can update the model.
*
* @param \App\User $user
* @param \App\User $model
* @return mixed
*/
public function update(User $user, User $model)
{
return true;
}

/**
* Determine whether the user can delete the model.
*
* @param \App\User $user
* @param \App\User $model
* @return mixed
*/
public function delete(User $user, User $model)
{
//
}

/**
* Determine whether the user can restore the model.
*
* @param \App\User $user
* @param \App\User $model
* @return mixed
*/
public function restore(User $user, User $model)
{
return true;
}

/**
* Determine whether the user can permanently delete the model.
*
* @param \App\User $user
* @param \App\User $model
* @return mixed
*/
public function forceDelete(User $user, User $model)
{
return true;
}
}
4 changes: 3 additions & 1 deletion src/LaravelRestifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class LaravelRestifyServiceProvider extends ServiceProvider
public function boot()
{
if ($this->app->runningInConsole()) {
$this->commands([CheckPassport::class]);
$this->commands([
CheckPassport::class,
]);
$this->registerPublishing();

$this->app->register(RestifyServiceProvider::class);
Expand Down
13 changes: 9 additions & 4 deletions src/Restify.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function repositoryForKey($key)
/**
* Get the repository class name for a given key.
*
* @param string $model
* @param string $model
* @return string
*/
public static function repositoryForModel($model)
Expand Down Expand Up @@ -109,11 +109,16 @@ public static function repositoriesFrom($directory)
/**
* Get the URI path prefix utilized by Restify.
*
* @param null $plus
* @return string
*/
public static function path()
public static function path($plus = null)
{
return config('restify.base', '/restify-api');
if (isset($plus)) {
return config('restify.base', '/restify-api').'/'.$plus;
} else {
return config('restify.base', '/restify-api');
}
}

/**
Expand All @@ -130,7 +135,7 @@ public static function starting($callback)
}

/**
* @param \Closure|string $callback
* @param \Closure|string $callback
*/
public static function beforeEach($callback)
{
Expand Down
34 changes: 34 additions & 0 deletions src/RestifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Binaryk\LaravelRestify;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

Expand Down Expand Up @@ -33,8 +34,41 @@ protected function registerRoutes()
'middleware' => config('restify.middleware', []),
];

$this->customDefinitions($config)
->defaultRoutes($config);
}

/**
* @param $config
* @return RestifyServiceProvider
*/
public function customDefinitions($config)
{
collect(Restify::$repositories)->filter(function ($repository) {
return isset($repository::$middleware) || isset($repository::$prefix);
})
->each(function ($repository) use ($config) {
$config['middleware'] = array_merge(config('restify.middleware', []), Arr::wrap($repository::$middleware));
$config['prefix'] = Restify::path($repository::$prefix);

Route::group($config, function () {
$this->loadRoutesFrom(__DIR__.'/../routes/api.php');
});
});

return $this;
}

/**
* @param $config
* @return RestifyServiceProvider
*/
public function defaultRoutes($config)
{
Route::group($config, function () {
$this->loadRoutesFrom(__DIR__.'/../routes/api.php');
});

return $this;
}
}