Giter VIP home page Giter VIP logo

annotations's Introduction

Annotations for The Laravel Framework

Build Status Total Downloads Latest Stable Version Latest Unstable Version License

Annotations

Installation

If you have changed the top-level namespace to something like 'MyCompany', then you would use the new namespace instead of 'App'.

Begin by installing this package through Composer. Edit your project's composer.json file to require laravelcollective/annotations.

"require": {
    "laravelcollective/annotations": "6.0.\*"
}

Next, update Composer from the Terminal:

composer update

Once composer is done, you'll need to create a Service Provider in app/Providers/AnnotationsServiceProvider.php.

<?php namespace App\Providers;

use Collective\Annotations\AnnotationsServiceProvider as ServiceProvider;

class AnnotationsServiceProvider extends ServiceProvider {

    /**
     * The classes to scan for event annotations.
     *
     * @var array
     */
    protected $scanEvents = [];

    /**
     * The classes to scan for route annotations.
     *
     * @var array
     */
    protected $scanRoutes = [];

    /**
     * The classes to scan for model annotations.
     *
     * @var array
     */
    protected $scanModels = [];

    /**
     * Determines if we will auto-scan in the local environment.
     *
     * @var bool
     */
    protected $scanWhenLocal = false;

    /**
     * Determines whether or not to automatically scan the controllers
     * directory (App\Http\Controllers) for routes
     *
     * @var bool
     */
    protected $scanControllers = false;

    /**
     * Determines whether or not to automatically scan all namespaced
     * classes for event, route, and model annotations.
     *
     * @var bool
     */
    protected $scanEverything = false;

}

Finally, add your new provider to the providers array of config/app.php:

  'providers' => [
    // ...
    App\Providers\AnnotationsServiceProvider::class
    // ...
  ];

This doesn't replace the RouteServiceProvider, this is still required as this handles loading of the route cache etc.

Setting up Scanning

Add event handler classes to the protected $scanEvents array to scan for event annotations.

    /**
     * The classes to scan for event annotations.
     *
     * @var array
     */
    protected $scanEvents = [
      App\Handlers\Events\MailHandler::class,
    ];

Add controllers to the protected $scanRoutes array to scan for route annotations.

    /**
     * The classes to scan for route annotations.
     *
     * @var array
     */
    protected $scanRoutes = [
      App\Http\Controllers\HomeController::class,
    ];

Add models to the protected $scanModels array to scan for model annotations.

    /**
     * The classes to scan for model annotations.
     *
     * @var array
     */
    protected $scanModels = [
      'App\User',
    ];

Alternatively, you can set protected $scanEverything to true to automatically scan all classes within your application's namespace. Note: This may increase the time required to execute the scanners, depending on the size of your application.

Scanning your event handlers, controllers, and models can be done manually by using php artisan event:scan, php artisan route:scan, or php artisan model:scan respectively. In the local environment, you can scan them automatically by setting protected $scanWhenLocal = true.

Event Annotations

@Hears

The @Hears annotation registers an event listener for a particular event. Annotating any method with @Hears("SomeEventName") will register an event listener that will call that method when the SomeEventName event is fired.

<?php namespace App\Handlers\Events;

use App\User;

class MailHandler {

  /**
   * Send welcome email to User
   * @Hears("UserWasRegistered")
   */
  public function sendWelcomeEmail(User $user)
  {
    // send welcome email to $user
  }

}

Route Annotations

Route annotations can be incredibly powerful, however the order of your route definitions can impact how your application matches specific routes, specifically any wildcard routes. If protected $scanEverything is set to true, you will have no control over the order of your route definitions.

@Get

The @Get annotation registeres a route for an HTTP GET request.

<?php namespace App\Http\Controllers;

class HomeController {

  /**
   * Show the Index Page
   * @Get("/")
   */
  public function getIndex()
  {
    return view('index');
  }

}

You can also set up route names.

  /**
   * @Get("/", as="index")
   */

... or middlewares.

  /**
   * @Get("/", middleware="guest")
   */

... or both.

  /**
   * @Get("/", as="index", middleware="guest")
   */

Here's an example that uses all of the available parameters for a @Get annotation:

  /**
   * @Get("/profiles/{id}", as="profiles.show", middleware="guest", domain="foo.com", where={"id": "[0-9]+"}, no_prefix="true")
   */

no_prefix allows any prefix added to the routes in that controller be ignored for this particular route.

@Post, @Options, @Put, @Patch, @Delete, @any

The @Post, @Options, @Put, @Patch, @Delete, and @Any annotations have the exact same syntax as the @Get annotation, except it will register a route for the respective HTTP verb, as opposed to the GET verb.

@Middleware

As well as defining middleware inline in the route definition tags (@Get, @Post, etc.), the @Middleware tag can be used on its own. It works both individual methods:

  /**
   * Show the Login Page
   *
   * @Get("login")
   * @Middleware("guest")
   */
  public function login()
  {
    return view('index');
  }

Or on a whole controller, with the same only/exclude filter syntax that you can use elsewhere in laravel:

/**
 * @Middleware("guest", except={"logout"}, prefix="/your/prefix")
 */
class AuthController extends Controller {

  /**
   * Log the user out.
   *
   * @Get("logout", as="logout")
   * @Middleware("auth")
   *
   * @return Response
   */
  public function logout()
  {
    $this->auth->logout();

    return redirect( route('login') );
  }

}

@Resource

Using the @Resource annotation on a controller allows you to easily set up a Resource Controller.

<?php
/**
 * @Resource('users')
 */
class UsersController extends Controller {
  // index(), create(), store(), show($id), edit($id), update($id), destroy($id)
}

You can specify the only and except arguments, just like you can with the regular Route::resource() command.

  /**
   * @Resource('users', only={"index", "show"})
   */

You can also specify the route names of each resource method.

  /**
   * @Resource('users', names={"index"="user.all", "show"="user.view"})
   */

@Controller

Using the @Controller annotation on a controller allows you to set various options for the routes contained in it:

<?php
/**
 * @Controller(prefix="admin", domain="foo.com")
 */
class AdminController extends Controller {
  // All routes will be prefixed by admin/
}

Scan the Controllers Directory

To recursively scan the entire controllers namespace ( App\Http\Controllers ), you can set the $scanControllers flag to true.

It will automatically adjust App to your app's namespace.

    $scanControllers = true;

Advanced

If you want to use any logic to add classes to the list to scan, you can override the routeScans() or eventScans() methods.

The following is an example of adding a controller to the scan list if the current environment is local:

public function routeScans() {
    $classes = parent::routeScans();

    if ( $this->app->environment('local') ) {
        $classes = array_merge($classes, [App\Http\Controllers\LocalOnlyController::class]);
    }

    return $classes;
}

Scanning Namespaces

You can use the getClassesFromNamespace( $namespace ) method to recursively add namespaces to the list. This will scan the given namespace. It only works for classes in the app directory, and relies on the PSR-4 namespacing standard.

This is what the $scanControllers flag uses with the controllers directory.

Here is an example that builds on the last one - adding a whole local-only namespace.

public function routeScans() {
    $classes = parent::routeScans();

    if ( $this->app->environment('local') ) {
        $classes = array_merge(
            $classes,
            $this->getClassesFromNamespace( App\Http\Controllers\Local::class )
        );
    }

    return $classes;
}

Model Annotations

You can use annotations to automatically bind your models to route parameters, using Route Model Binding. To do this, use the @Bind annotation.

/**
 * @Bind("users")
 */
class User extends Eloquent {
  //
}

This is the equivalent of calling Route::model('users', 'App\Users').

Custom Annotations

If you want to register your own annotations, create a namespace containing subclasses of Collective\Annotations\Routing\Annotations\Annotations\Annotation - let's say App\Http\Annotations.

Then, in your annotations service provider, override the addRoutingAnnotations( RouteScanner $scanner ) method, and register your routing annotations namespace:

<?php namespace App\Providers;

use Collective\Annotations\Routing\Annotations\Scanner as RouteScanner;

/* ... then, in the class definition ... */

    /**
     * Add annotation classes to the route scanner
     *
     * @param RouteScanner $namespace
     */
    public function addRoutingAnnotations( RouteScanner $scanner )
    {
      $scanner->addAnnotationNamespace( 'App\Http\Annotations' );
    }

Your annotation classes must must have the @Annotation class annotation (see the following example).

There is an equivalent method for event annotations: addEventAnnotations( EventScanner $scanner ).

Custom Annotation Example

Here is an example to make an @Auth annotation. It provides the same functionality as using the annotation @Middleware("auth").

In a namespace - in this example, App\Annotations:

<?php namespace App\Http\Annotations;

use Collective\Annotations\Routing\Annotations\Annotations\Annotation;
use Collective\Annotations\Routing\Annotations\MethodEndpoint;
use ReflectionMethod;

/**
 * @Annotation
 */
class Auth extends Annotation {

  /**
   * {@inheritdoc}
   */
  public function modify(MethodEndpoint $endpoint, ReflectionMethod $method)
  {
    if ($endpoint->hasPaths())
    {
      foreach ($endpoint->getPaths() as $path)
      {
        $path->middleware = array_merge($path->middleware, (array) 'auth');
      }
    }
    else
    {
      $endpoint->middleware = array_merge($endpoint->middleware, (array) 'auth');
    }
  }

}

annotations's People

Contributors

adamgoose avatar alexfoo avatar alies-dev avatar anahkiasen avatar arrilot avatar chrispecoraro avatar deriel avatar gabrielkoerich avatar grummfy avatar ionutbajescu avatar johntimothybailey avatar jpcaparas avatar loonytoons avatar mauroveron avatar mlantz avatar mrsimonbennett avatar r4w-dev avatar rodrigolinsr avatar somoza avatar tedslittlerobot avatar tshafer avatar vesper8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

annotations's Issues

Middleware parameters

Hi!
Is there a way to pass a middleware parameter using the @Middleware annotation?
(docs don't have info on that & skimming the package code hasn't helped as well)

Limit the scanEverything method

I think that we should have an option to scan only certain namespaces. (like App\Models, App\Http\Controllers - you get the idea)

In the current state, $scanEverything takes 4 seconds of the booting load which is enormous and makes the development impossible.

If no one has something against this feature I'll do a pull request as soon as possible.

Lumen Support?

Would it be possible to support Lumen? As of current it is not.

AnnotationScanner's Reflection exception squashing is too broad

I just spent a few hours debugging, trying to figure out why one of my route model bindings was suddenly not working. I finally traced it to an exception that was being squashed in
\Collective\Annotations\AnnotationScanner::getClassesToScan.

It was trying to create a ReflectionClass for a class in which I had added a child method with a slightly different signature, so it was throwing an exception. This could be a bug in ReflectionClass, since according to the documentation, it's only supposed to throw if the class doesn't exist, but it seems to be trying to instantiate it in the process.

Instead of catching \Exception, we should catch \ReflectionException so that other errors can bubble up. I thought it might help someone experiencing a similar, frustrating situation!

[Idea] event:list

What do you think to the idea of listing all events in a CLI table.

annotation route cache

I have some simple annotations setup with laravel 5.2

@Get("/", as="home")
@Get("/about", as="about")
@Get("/contact", as="contact")

routes are scanned and routes show in route:list command, but after perform a route:cache, no route is found and causes a NotFoundHttpException. is this an intended behaviors?

Add ability to specify method for @Bind

Example:

/**
 * @Bind("user", with="findBySlug")
 */
class User extends Model
{
  // ...
}

Translating to

$router->bind('user', 'User@findBySlug')

Currently if you don't use the default find method, you can't use the annotation.

@Middleware not inherited from parent class

If you are using a base class to accomplish route "groups" for middle ware the annotation isnt inherited

<?php
namespace App\Http\Controllers;
/**
 * @Middleware("auth")
 */
class BaseController
{
    ...
}


<?php
namespace App\Http\Controllers;

class SomeController extends BaseController
{
    /**
     * @Get("/some-path")
     */
    public function index()
    {
        ....
    }
}

Running php artisan route:scan completes without errors but php artisan route:list shows the route without the middleware.

Is this working as intended or a bug?

Annotation must be quoted by double quotes

/**
 * @Resource('photos')
 */
class PhotoController extends Controller{}

If annotation is quoted by single quotes, php artisan route:scan will throw an exception:

  [Doctrine\Common\Annotations\AnnotationException]
  [Syntax Error] Expected PlainValue, got ''' at position 10 in class App\Http\Controllers\PhotoController.

@Any annotation

Currenly registering both get and post with an annotation looks like this:
img

For interoperability we should add the @Any annotation.

I'll be back soon with a pull request for this feature.

Defining parent method disables annotated routes

All of my controllers extend an abstract base controller. If I define an update() method in that base controller, route annotations stop working on all controllers that extend from that base. I'm using @resource controllers. There are no route annotations at all in the base controller. If I try to add a route annotation (e.g. @get) to the update() method in the base controller, the route does show up, and picks my last (alphabetically) child controller's update method as the action.

If I change the name of the update method in my parent controller, everything works fine, so I will do that for now as a temporary work-around.

Laravel Annotation commands

function fire of commands EventScanCommand.php, ModelScanCommand.php, RouteScanCommand.php should be renamed to handle

Laravel 7 compatibility

6.0 is not compatible with Laravel 7 due to illuminate/filesystem ^6.0

@mlantz Any chance you could release a new version with Laravel 7 compatibility like you did 5 months ago for Laravel 6?

That would be great!!! Thanks!

[features]Route scanning inside route definition

Hello,

So grouping with annotation is something that's missing.

  1. So I got a first idea. In a route file, declaring something like this :
Route::group(['prefix' => 'foo'], function ()
{
  Route::scan(app_path('Http/Controllers/Foo'));
});

So, it will scan the Foo directory and all route given by the annotation will inherit of group property (middleware, prefix, etc). So if we find a method or a controller with a prefix, it will be added, etc.
So, for sure we will require to cache this to avoid losing a lot of time...

πŸ‘ All route are "defined" in same place.
πŸ‘Ž Can make really slow system if many stuff to scan

  1. Another way of doing it, could be, grouping Controller of a group inside a directory, and all annotated controller of this directory will got some properties. So inside the AnnotationsServiceProvider we should get something like
	protected $scanRoutesGroupsByDirectory = [
		'Foo' => ['prefix' => 'foo', 'midleware' => ['auth', 'another-middleware']],
	];

πŸ‘ Work in the same way as now
πŸ‘Ž Route are define in two spot

  1. Create a toScan.php file inside the routes directory with a structure like this
return [
	'*' => [ // on all annotated controller & method, add these properties
		'middleware' => ['auth', 'trim'],
	],
	'Foo' => [ // on annotated controller & method inside the directory Foo add these properties
		'prefix' => 'foo'
	]
	'Bar', // scan Bar directory
	'BazController.php' // scan these controller
];

πŸ‘ All route are define inside one directory, we keep the scan command to have theses routes

So what do you think about theses ideas?

Laravel 5.1 support?

I see laravelcollective/html is already supporting 5.1 but annotations is not, is there a major blocking point preventing support currently?

ClassFinder.php removed in laravel 5.4

In Laravel 5.4 the Illuminate\Filesystem\ClassFinder.php was removed.

Annotations use this class and nothing works!

Class Illuminate\Filesystem\ClassFinder does not exist

Add @Composes annotation

For view composers:

/**
 * @Composes("some/view")
 */
class MyComposer
{
  public function compose(View $view)
  {
    // ...
  }
}

class AdminComposer
{
  /**
   * @Composes({"admin/foo", "admin/bar"})
   */
  public function composeFoo(View $view)
  {
    // ...
  }

  /**
   * @Composes("bar")
   */
  public function composeBar(View $view)
  {
    // ...
  }
}

Would be nice in my opinion, what do you think?

what is proper way to implement the 'web' middleware group introduced in laravel 5.2?

I'm having a hard time understanding how to make a whole controller require auth now that the 'web' middleware group was introduced in 5.2

It seems that the way that is intended is to put all the routes inside of a

Route::group(['middleware' => 'web'], function() {

    // Existing routes go here

});

But how does that translate to annotations?

Laravel 5.6: "file_get_contents(/var/www/vhosts/webrising.nl/laravel/composer.json): failed to open stream: No such file or directory"

Hello,

I tried to install the plugin with version 5.6 of laravel. But I've got an error when setting scanControllers in AnnotationsServiceProvider to "true". So far I tried to install version 5.6 and 5.6.x-dev, both the same error.

ErrorException thrown with message "file_get_contents(/var/www/vhosts/webrising.nl/laravel/composer.json): failed to open stream: No such file or directory"

Stacktrace:
#20 ErrorException in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1154
#19 file_get_contents in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1154
#18 Illuminate\Foundation\Application:getNamespace in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Console/DetectsApplicationNamespace.php:16
#17 Collective\Annotations\AnnotationsServiceProvider:getAppNamespace in /var/www/vhosts/webrising.nl/laravel/vendor/laravelcollective/annotations/src/AnnotationsServiceProvider.php:451
#16 Collective\Annotations\AnnotationsServiceProvider:routeScans in /var/www/vhosts/webrising.nl/laravel/vendor/laravelcollective/annotations/src/AnnotationsServiceProvider.php:323
#15 Collective\Annotations\AnnotationsServiceProvider:loadAnnotatedRoutes in /var/www/vhosts/webrising.nl/laravel/vendor/laravelcollective/annotations/src/AnnotationsServiceProvider.php:118
#14 Collective\Annotations\AnnotationsServiceProvider:boot in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
#13 call_user_func_array in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:29
#12 Illuminate\Container\BoundMethod:Illuminate\Container{closure} in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:87
#11 Illuminate\Container\BoundMethod:callBoundMethod in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php:31
#10 Illuminate\Container\BoundMethod:call in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Container/Container.php:564
#9 Illuminate\Container\Container:call in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:794
#8 Illuminate\Foundation\Application:bootProvider in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:777
#7 Illuminate\Foundation\Application:Illuminate\Foundation{closure} in [internal]:0
#6 array_walk in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:778
#5 Illuminate\Foundation\Application:boot in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/BootProviders.php:17
#4 Illuminate\Foundation\Bootstrap\BootProviders:bootstrap in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:206
#3 Illuminate\Foundation\Application:bootstrapWith in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:162
#2 Illuminate\Foundation\Http\Kernel:bootstrap in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:146
#1 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /var/www/vhosts/webrising.nl/laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#0 Illuminate\Foundation\Http\Kernel:handle in /var/www/vhosts/webrising.nl/laravel/public/index.php:55

With kind regards,

Rick

Issues with routes when being called from within the framework

If I use the framework's test methods to make a call to either a controller action or a route, I see the following error:

PHP Fatal error:  Call to a member function domain() on null in vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 440

This does not happen if I do not use annotations.

Using literal quotes breaks the package

If I do the following:

/**
 * @Middleware('shift.account')
 */
class RegistrationController extends Controller
{

It results in the following error:

[Syntax Error] Expected PlainValue, got ''' at position 12 in class AwardForce\Http\Controllers\RegistrationController.

This is easily solved by using double quotes ("") however - this was not clear at all initially. Both single and double quotes should be supported. In fact, because there are no variables - single quotes should even be the default (to match the language).

Bug when update to Laravel v5.0.21.

When I update to Laravel 5.0.21 the command 'php artisan route:scan' and 'php artisan route:list' dont work anymore. I get this error:

[Symfony\Component\Debug\Exception\FatalErrorException]  
    Call to a member function routeScans() on a non-object 

[Proposal] Route Model Binding

So here's the idea... When you register a resource controller with the @Resource annotation, I think it'd be nice to be able to specify the model that the resource is for. For example...

/**
 * @Resource("users", model="App\User")
 */
class UsersController extends Controller {
    // Resource Controller Methods
}

This would register routes in the following fashion:

  $route->resource('users', [{Users Controller Definition}]);

  $route->model('users', 'App\User');

Please share your thoughts and help me determine if...

  1. This is a good place to put such an annotation.
  2. It'd even be helpful to anyone.

Thanks,
Adam.

@Prefix annotation

This would be nice for controllers, PHP equivalent of doing per example:

Route::group(['prefix' => 'admin'], function() {
  Route::get('foo', 'AdminController@foo');
  Route::get('bar, 'AdminController@bar');
});

Now you'd have

/**
 * @Prefix("admin")
 */
class AdminController
{
  // ...
}

Multiple annotation providers

I've tried to register multiple annotation providers, in result only last registered worked. Is there any workaround?

how to set patterns for wildcards in annotations?

I'm using many wildcards and getting some mismatching which would be solved if patterns were respected

for example I have these two routes

/{any}/{page}
and
/{any}/{name}

going to /something/12 should hit the first route
and going to /something/name should hit the 2nd route

regardless of what order they are defined in

I tried adding

Route::pattern('page', '[0-9]+');

to the RouteServiceProvider

which is supposed to enforce that the {page} argument must always be fully numerical in order for that route to be matched.. but it's not working

Do you know if using annotations for my routes with this package is ignoring patterns set in the RouteServiceProvider?

And is there a way then to set regex patterns for wildcard routes directly in the annotations?

Or another solution?

Many thanks!

Route model binding is ignored in one controller

This is a really odd issue. I've defined a binding in my model. On my local installation, this works perfectly for both my admin and api controllers. I've just deployed this project to a dev server, and the binding works fine on the api routes, but is ignored on the admin routes. A plain ID string is being passed into my controller methods instead of the respective model. I cannot account for this.

The code is the same and I've cleared every cache I can find. What could be causing this discrepancy? Both the working (api) and non-working (admin) controllers are defined in exactly the same way, and using the same model binding. If I add the binding manually in my RouteServiceProvider, it again works just fine.

I've had no luck debugging this myself. Appreciate any insights!

Route Model Binding Idea

Hey!

Can annotations work as an interface?

Like if you could say that when you have a @BindModel that you have to implement a method in that model like

/**
 * @Bind("username")
 */
class User extends Eloquent {

  public function bindModel($param) // username
  {
    return $this->where('username', '=', $param)->first();
  }

}

And if you use routes you have this:

get("/users/{username}", "UsersController@show");

If you use it this way, you are not limited to

User::find($x);

What do you guys think? :)

Strange error on production server only

Read this on Laracasts forum: https://laracasts.com/discuss/channels/laravel/blank-page

I just uploaded a commit to my server, but now one page is completely blank. It works without problems on my dev server.

I get no errors in laravel.log nor in Apache's error.log.

I have tried `sudo chmod -R 777 bootstrap/cache storageΒ΄

I have also tried php artisan cache:clear and composer clearcache

That one page is still blank, the rest works fine. It's all pages under the domain path domain/settings/[HERE] that are broken with just a white page.

If I add some gibberish to the controller like die('TEST'); the page is still blank.

Hope anyone has an idea because I'm stuck now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.