Class 'Modules\Media' not found in eval()'d code on line 1 in Laravel after installing laravel-modules by nWidart - class

I'm using nWidart's laravel-modules for a project. The idea is great but I don't like having the modules directory starting with a capital letter (Modules).
I decided to change the directory name in the configuration file:
/config/modules.php
I kept the namespace as Modules, but I changed path:
return [
'namespace' => 'Modules',
'paths' => [
'modules' => base_path('modules'), // Used to be ('Modules')
]
];
I added this to the composer.json file:
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "modules/"
}
},
Now, I created a Module called Media:
php artisan module:make Media
And also created a model Media:
php artisan module:make-model Media media
My model goes like this:
<?php
namespace Modules\Media\Entities;
use Illuminate\Database\Eloquent\Model;
class Media extends Model{
//
public function categories(){
return $this->belongsToMany( Category::class, 'category_media' );
}
}
Everything works fine, but when I go to tinker
php artisan tinker
And I try to load an Object (which exists) from the database:
$file = \Modules\Media\Entities::find( 1 );
or
$file = Modules\Media\Entities::find( 1 );
or
$file = modules\Media\Entities::find( 1 );
or
$file = \modules\Media\Entities::find( 1 );
I get this error:
PHP Fatal error: Class 'Modules\Media\Entities' not found in eval()'d code on line 1
Any ideas on what might be causing the problem? was it the changeof the directory name? Am I missing something in the composer.json configuration? I have no idea.

After reading my own code, I figured out that I was not referencing the Class, but only the namespace. The correct way to call the Media class was:
$file = \Modules\Media\Entities\Media::find( 1 );
(Notice that this time I end with \Media)
And of course, the result is the expected:
=> Modules\Media\Entities\Media {#857
id: 1,
filename: "my_file.jpg",
properties: "[]",
mime: "image\jpg",
extension: "jpg",
created_at: "2017-05-21 04:37:28",
updated_at: "2017-05-21 04:37:28",
published: 0,
published_at: "2017-05-20 23:37:28",
}

Related

url-loader without webpack?

I have a component library that will be shipping with a few small assets (images). Those assets are imported into various components in the library.
The build script uses babel (without webpack) to transpile the js(x) to a build directory, and is currently dumping the images into build/assets/images.
This works when testing the build, but when using the component in another project (using webpack) the component tries to refer the node_modules folder:
Example component:
import myImage from './assets/images/myImage.png';
const MyComponent = () => (
<img src={myImage} />
);
export MyComponent;
Usage:
import MyComponent from 'myLibrary/MyComponent';
export default () => (
<MyComponent />
);
The error message:
myImage.png:1 GET http://localhost:9001/node_modules/myLibrary/assets/images/myImage.png 404 (Not Found)
As I understand the 'best' way to include assets is to use the url-loader so they're converted to data uri's. However, trying to use the url-loader without Webpack isn't working:
babel.config.js
...
plugins: [
[
"url-loader",
{
"extensions": ["png", "jpg", "jpeg", "gif", "svg", "pdf"],
"limit": 0
}
]
]
...
Error: Cannot find module 'babel-plugin-url-loader'
I found this and it works for PNG and SVG files - worked perfectly for what I needed!
https://www.npmjs.com/package/babel-plugin-inline-import-data-uri

tymon jwt-auth laravel 5.4 error

I am getting this error after composer update....
I am using laravel version 5.4.*
Call to undefined method Illuminate\Foundation\Application::share()
My providers array
`'providers' => [App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
'Tymon\JWTAuth\Providers\JWTAuthServiceProvider'
],`
My alias array
'aliases' => ['View' => Illuminate\Support\Facades\View::class,
'JWTAuth' => 'Tymon\JWTAuth\Facades\JWTAuth',
'JWTFactory' => 'Tymon\JWTAuth\Facades\JWTFactory'
],
My composer.json
,
"tymon/jwt-auth": "0.5.*"
The error is
C:\wamp\www\myproject\app>php artisan vendor:publish --provider="Tymon\JW
TAuth\Providers\JWTAuthServiceProvider"
PHP Fatal error: Call to undefined method Illuminate\Foundation\Application::sh
are() in C:\wamp\www\myproject\app\vendor\tymon\jwt-auth\src\Providers\JW
TAuthServiceProvider.php on line 122
Use dev-master branch. Edit yout composer json file.
"require": {
...
"tymon/jwt-auth": "dev-master"
...
},
and composer update
When you want to add a provider in app.php the code is like this:
ProviderPath/ProviderName::class,
Change this line:
'providers' => [App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
'Tymon\JWTAuth\Providers\JWTAuthServiceProvider'//this one
],
to
'providers' => [App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Tymon\JWTAuth\Providers\JWTAuthServiceProvider::class //this one
],

Puppet PostgresQL management

I am trying to provision an EC2 instance using puppet. In the process I have downloaded the puppetlabs-postgresql module from puppetlabs. Since I'm fairly new to puppet, i do not want to manage my database by creating classes in my site.pp file located in /etc/puppet/manifests/site.pp. Rather I want to have a module call database in /etc/puppet/modules/database.
What I have done so far is create an init.pp file in /etc/puppet/modules/database. Below is the content of my init.pp file :
class database {
# resources
postgresql::globals{'globals':
version => '9.3',
manage_package_repo => true,
encoding => 'UTF8',
locale => 'it_IT.utf8',
}
postgresql::server{'server':
ensure => 'present',
listen_addresses => '*',
manage_firewall => true,
}
postgresql::server::contrib{'contrib':
package_ensure => 'present',
}
}
And then in my /etc/puppet/manifests/site.pp file i have included the database class as below :
node default {
include localusers
include database
}
However i keep getting an error :
Error: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type postgresql::globals at /etc/puppet.manifests/init.pp:12
Please what is the correct way to make use of the postgresql classes and resources in my own module and create a database in the module as well ?
You're on the right track, but there are a few issues with how you're using the postgresql module. The reason you're getting the Invalid resource type error is that you're trying to use postgresql::globals as a defined type when it's actually a class. You have the same issue with the other two classes you're using. Try this...
class database {
# set global defaults before creating server
class { 'postgresql::globals':
version => '9.3',
manage_package_repo => true,
encoding => 'UTF8',
locale => 'it_IT.utf8',
}->
class { 'postgresql::server':
listen_addresses => '*',
manage_firewall => true,
}
# install the postgresql contrib package
class { 'postgresql::server::contrib':
package_ensure => 'present',
}
# create database with user and default permissions
postgresql::server::db { 'my_awesome_db':
user => 'my_db_user',
password => 'puppetRocks',
}
}
In the reference section of the module documentation, there's a breakdown of the classes and resources (a.k.a. defined types). The postgresql::server::db type that I used is the simplest way to create a database, user, and permissions all at once. There are separate types available for each of those to provide more fine-grained control.

Overwrite if if it exists or create if it does not

I am trying to rewrite a file using puppet with the following function.
If the file exists I still want the file to be rewrite from the source. Will this be achieved with the following method?
define setup_sysctl_conf( $dependence=File[$dummy_dependence_file] )
{
file { $name:
path => '/etc/sysctl.conf',
ensure => present,
mode => 0777,
source => '/vagrant/files/sysctl.conf',
require => $dependence,
}
}
The file: /etc/sysctl.conf will already be present on your host (created by the initscripts package).
I would recommend to modify existing files with puppet using augeas instead of replacing them.
Example (changes net.ipv4.ip_forward to 1):
class sysctl_augeas_example {
augeas{"Set net.ipv4.ip_forward to 1":
context => "/files",
changes => [
"set etc/sysctl.conf/net.ipv4.ip_forward 1",
]
}
}
include sysctl_augeas_example
Save this example as test.pp and run it with puppet apply test.pp

Vagrant Puppet Provisioning failure due declarative structure

As the title describes I am having an issue provisioning a box successfully. I am trying to install a development box (Apache, PHP and XDebug)
Everything works fine except for the point where I have to include the XDebug functionality, since it is not supplied in the original REPO I am installing it through the Example42/puppet-yum REPO manager.
In this part there is a mistake, since when I try to build the box from scratch I get the the error that package php-perl-xdebug is not available. This is because the repo's are not yet initialized. I have tried several ways to make sure that it would update the repo's before doing any other action. Referencing the classes by -> but this would yield in a looped block. Going through Google did not yield any practical results that would make sure that some commands are ran before others.
I believe it is possible to do this wit the "Required" command, but I could't find a way to use it.
Side note: We're mostly using example42 modules for our building.
Thanks in advance:
The following is the default.pp manifest for the application service.
default.pp
Exec { path => [ "/bin/", "/sbin/" , "/usr/bin/", "/usr/sbin/" ] }
class system-setup {
service { "iptables":
ensure => stopped,
}
}
class php-setup{
php::module { "pdo": }
php::module { "gd": }
# php::module { "fpm": }
php::module { "mysql": }
php::module { "soap": }
# php::module { "zts": }
# php::module { "pecl-apc": }
php::module { "pecl-memcache": }
php::module { "xml": }
php::module{ "pecl-xdebug": }
}
class apache-vhost {
apache::vhost { 'trunk.project.dev':
docroot => '/var/www/html/',
port => '80',
}
}
class { 'yum':
extrarepo => [ 'epel' ],
}
class { 'apache':
source => [ "puppet:///modules/apache/httpd.conf-project" , "puppet:///modules/apache/httpd.conf" ],
}
class { 'php' :
source => ["/vagrant/files/php.ini", "puppet:///modules/php/php.ini"],
}
include php-setup
include apache-vhost
You can put this somewhere:
Class['yum'] -> Package <||>
This is using a resource collector to make sure Class yum is done before any package is installed.