0

Suppose I have this Facade in one of my module:

// workbench/vendor/module1/src/Vendor/Module1/Facades/Module1.php

<?php namespace Vendor\Module1\Facades;

use Illuminate\Support\Facades\Facade;

class Module1 extends Facade {

  /**
   * Get the registered name of the component.
   *
   * @return string
   */
  protected static function getFacadeAccessor() { return 'module1'; }

}

And I create an Eloquent of the same module, like this:

// workbench/vendor/module1/src/models/Module1.php

<?php

class Module1 extends \Eloquent {

    protected $table = 'tb_module_1';

}

When I'm trying to call Module1 in my code that was intended to Eloquent, ex. $module1 = new Model1, it returns a Facade instead of Eloquent (ex. I can't use $module1->save()).

How to make Eloquent and Facade works in module development of Laravel? (If there are any suggestion that it is pointless to use both Eloquent and Facade, I would really love to hear the opinion)

user2002495
  • 2,126
  • 8
  • 31
  • 61
  • I don't understand why you're creating a facade with the same name as the model? What's the purpose of the facade? What do you intend to do with it? – davidnknight Jun 04 '14 at 14:00
  • @davidnknight: it is for the same module, is it really pointless to create Facade and Eloquent together (or just Eloquent is enough) for a single module? – user2002495 Jun 04 '14 at 14:14
  • @davidnknight: my point of creating facade is that i am able to use view from each module, so if I name my `Facade` of `Module1` as `module1`, and i have a view in it, i can use the view in other modules like: `@include('module1::myview')` <-- if you got a way for this working in `Eloquent` I would love to hear it – user2002495 Jun 04 '14 at 14:18
  • I really don't understand why you'd want to create a view on the model. The model should do nothing more than represent what the object looks like, including its attributes and relationships, anything else should be moved out to repositories, interfaces and presenters etc. If I'm understanding correctly, you want to create views for each object but rather than just creating files in your app/views folder, you're for some reason trying to add them via static methods on the model. Am I correct in my understanding? If so, why this way? – davidnknight Jun 04 '14 at 15:11
  • @davidnknight: the accepted answer from here is close to what i want, thanks: http://stackoverflow.com/questions/16957790/how-do-i-create-a-facade-class-with-laravel – user2002495 Jun 05 '14 at 06:15

0 Answers0