I am implementing versioning in Laravel. Now my doubt is, where should I create the V1 subfolders within the various main folders? For example, is it okay for controllers (Controllers/Api/V1) but what about Models, Resources, Request, Services etc...?
There is a very well maintained package specifically for what you are trying to do, called Laravel Modules: https://github.com/nWidart/laravel-modules
You can accomplish subversions of the application inside of it, and everything like "Models, Resource, Routes, etc.." is packaged seperately from one module to another.
Modules/
├── Blog/
├── Config/
├── Console/
├── Database/
├── factories/
├── Migrations/
├── Seeders/
├── Entities/
├── Http/
├── Controllers/
├── Middleware/
├── Requests/
├── Providers/
├── PostsServiceProvider.php
├── RouteServiceProvider.php
├── Resources/
├── assets/
├── lang/
├── views/
├── Routes/
├── api.php
├── web.php
├── Tests/
├── composer.json
├── module.json
├── package.json
├── webpack.mix.js
Check the documentation on how to use it: https://docs.laravelmodules.com/v9/creating-a-module
Also laravel-daily made a video on what it is here: https://www.youtube.com/watch?v=RVApkrYMcAg
I compiled my styles and scripts using webpack, but I noticed that the libs.css and libs.js files are empty rather I have entries in the app.cs and app.js files. Here are my npm settings:
:- webpack.mix.js:
const { mix } = require('laravel-mix');
mix.js('resources/assets/js/app.js', 'public/js/')
.sass('resources/assets/sass/app.scss', 'public/css/');
mix.styles([
'libs/animate.css',
'libs/animations.css',
'libs/app.css',
'libs/bootstrap-theme.css',
'libs/bootstrap.css',
'libs/custom.css',
'libs/font-awesome.min.css',
'libs/head-custom.css',
'libs/sb-admin-2.css',
'libs/sticky.css',
'libs/style.css',
], './public/css/libs.css');
mix.scripts([
'libs/app.js',
'libs/bootstrap.js',
'libs/custom.js',
'libs/gmap.js',
'libs/ipad.js',
'libs/jquery.form.min.js',
'libs/jquery.min.js',
'libs/jquery.pjax.js',
'libs/jquery.slim.min.js',
'libs/myform.js',
'libs/sb-admin-2.js',
'libs/sb-admin-2.min.js',
'libs/sticky.js',
'libs/template.js',
], './public/js/libs.js');
mix.scripts([
'/plugins/jquery.appear.js',
'/plugins/jquery.backstretch.min.js',
'/plugins/modernizr.js',
'/plugins/libs3/jquery.js',
], './public/js/plugins/plugins.js');
mix.scripts([
'/libs/isotope.pkgd.js',
], './public/js/plugins/isotope/isotope.js');
:- mix-manifest.json:
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css",
"./public/css/libs.css": "./public/css/libs.css",
"./public/js/libs.js": "./public/js/libs.js",
"./public/js/plugins/plugins.js": "./public/js/plugins/plugins.js",
"./public/js/plugins/isotope/isotope.js": "./public/js/plugins/isotope/isotope.js"
}
:- Directory structure of resource folder:
resources/
├── assets
│ ├── css
│ │ └── libs
│ │ ├── animate.css
│ │ ├── animations.css
│ │ ├── app.css
│ │ ├── bootstrap.css
│ │ ├── bootstrap.min.css
│ │ ├── bootstrap-theme.css
│ │ ├── bootstrap-theme.min.css
│ │ ├── custom.css
│ │ ├── font-awesome.min.css
│ │ ├── head-custom.css
│ │ ├── sb-admin-2.css
│ │ ├── sb-admin-2.min.css
│ │ ├── sticky.css
│ │ └── style.css
│ ├── js
│ │ ├── app.js
│ │ ├── bootstrap.js
│ │ ├── components
│ │ │ └── Example.vue
│ │ ├── libs
│ │ │ ├── app.js
│ │ │ ├── bootstrap.js
│ │ │ ├── custom.js
│ │ │ ├── gmap.js
│ │ │ ├── ipad.js
│ │ │ ├── isotope.pkgd.js
│ │ │ ├── jquery.form.min.js
│ │ │ ├── jquery.min.js
│ │ │ ├── jquery.pjax.js
│ │ │ ├── jquery.slim.min.js
│ │ │ ├── myform.js
│ │ │ ├── sb-admin-2.js
│ │ │ ├── sb-admin-2.min.js
│ │ │ ├── sticky.js
│ │ │ └── template.js
│ │ └── plugins
│ │ ├── jquery.appear.js
│ │ ├── jquery.backstretch.min.js
│ │ ├── libs3
│ │ │ └── jquery.js
│ │ └── modernizr.js
│ └── sass
│ ├── app.scss
│ └── _variables.scss
Try this code below...
mix.styles(['resources/assets/css/libs/animate.css', 'resources/assets/css/libs/animations.css', 'resources/assets/css/libs/app.css', 'resources/assets/css/libs/bootstrap-theme.css', 'resources/assets/css/libs/bootstrap.css', 'resources/assets/css/libs/custom.css', 'resources/assets/css/libs/font-awesome.min.css', 'resources/assets/css/libs/head-custom.css', 'resources/assets/css/libs/sb-admin-2.css', 'resources/assets/css/libs/sticky.css', 'resources/assets/css/libs/style.css' ], 'public/css/libs.css', './');
mix.scripts(['resources/assets/js/libs/app.js', 'resources/assets/js/libs/bootstrap.js', 'resources/assets/js/libs/custom.js', 'resources/assets/js/libs/gmap.js', 'resources/assets/js/libs/ipad.js', 'resources/assets/js/libs/jquery.form.min.js', 'resources/assets/js/libs/jquery.min.js', 'resources/assets/js/libs/jquery.pjax.js', 'resources/assets/js/libs/jquery.slim.min.js', 'resources/assets/js/libs/myform.js', 'resources/assets/js/libs/sb-admin-2.js', 'resources/assets/js/libs/sb-admin-2.min.js', 'resources/assets/js/libs/sticky.js', 'resources/assets/js/libs/template.js' ], 'public/js/libs.js', './');
I think all paths should be relative to the root of the project (where webpack.mix.js is). Try
mix.styles([
'resources/assets/css/libs/animate.css',
//...
], 'public/css/libs.css')
mix.scripts([
'resources/assets/js/libs/app.js',
//...
], 'public/js/libs.js')
After much research I was able to use a laravel project to determine the reason for the empty files. The right syntax should have bee some like this:
mix.js('resources/assets/js/app.js', 'public/js/libs.js')
.sass('resources/assets/sass/app.scss', 'public/css/libs.css');
I should have specified destination file, so the right syntax would be some thing similar to:
```
const { mix } = require('laravel-mix');
mix
.js('resources/assets/js/app.js', 'public/js/app.js')
.js('resources/assets/js/bootstrap.js', 'public/js/app.js')
.js('resources/assets/js/plugins/jquery.appear.js', 'public/js/plugins/jquery.appear.js')
.js('resources/assets/js/plugins/jquery.backstretch.min.js', 'public/js/plugins/jquery.backstretch.min.js')
.js('resources/assets/js/plugins/modernizr.js', 'public/js/plugins/modernizr.js')
.combine([
'resources/assets/js/libs/app.js',
'resources/assets/js/libs/bootstrap.js',
'resources/assets/js/libs/custom.js',
'resources/assets/js/libs/gmap.js',
'resources/assets/js/libs/ipad.js',
'resources/assets/js/libs/jquery.form.min.js',
'resources/assets/js/libs/jquery.min.js',
'resources/assets/js/libs/jquery.pjax.js',
'resources/assets/js/libs/jquery.slim.min.js',
'resources/assets/js/libs/myform.js',
'resources/assets/js/libs/sb-admin-2.js',
'resources/assets/js/libs/sb-admin-2.min.js',
'resources/assets/js/libs/sticky.js',
'resources/assets/js/libs/template.js',], 'public/js/libs/libs.js')
.js('resources/assets/js/isotope/isotope.pkgd.min.js', 'public/js/plugins/isotope/isotope.pkgd.min.js')
.sass('resources/assets/sass/app.scss', 'public/css/lib.css')
.version();
```
The combine syntax should have been used to combine my javascript files.
Help source:
https://github.com/udoyen/blender
I' m trying to set up FOSUserBundle for my new application, so I want to override the default FOSUser form. As stated in the FOSUser documentation, I have to define my new form as a service before set up the app/config.yml appropriately. My question is why can't I just set up config.yml like this:
fos_user:
db_driver: orm
firewall_name: admin_area
user_class: abc\abcBundle\Entity\User
registration:
form:
type: abc\abcBundle\Form\Type\UserType
In my last application, I used FOSUserBundle along with PUGXMUltiUserBundle and then my (perfectly working) configuration for PUGXM was:
users:
agents:
entity:
class: abc\NikBundle\Entity\agents
registration:
form:
type: abc\NikBundle\Form\Type\UserType
name: agent_user_registration_form
template: abcNikBundle:ManageUsers:newUser.html.twig
so I supposed this can also be done with FOSUserBundle. Is it impossible and if yes why?
FOSUserBundle allows you to override it's controllers as described in the doc below
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_controllers.md
This doc actually shows you how to override registration controller and from there it's simply injecting your custom form for validation as in any normal controller.
You can also override the templates by finding the original FOSUserBundle templates under "{ROOT_DIR}/vendor/friendsofsymfony/user-bundle/Resources/views" and copying them into "{ROOT_DIR}/app/Resources/FOSUserBundle/views".
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_templates.md
It should look like this
Resources
└── FOSUserBundle
└── views
├── ChangePassword
│ ├── changePassword.html.twig
│ └── changePassword_content.html.twig
├── Registration
│ ├── confirmed.html.twig
│ ├── register.html.twig
│ └── register_fail.html.twig
├── Resetting
│ ├── checkEmail.html.twig
│ ├── email.txt.twig
│ ├── passwordAlreadyRequested.html.twig
│ ├── request.html.twig
│ ├── request_content.html.twig
│ ├── reset.html.twig
│ └── reset_content.html.twig
├── Security
│ └── login.html.twig
└── layout.html.twig
I've made a PHP application with Silex. I'm using a WAMP solution on my laptop to develop, in combination with Composer.
Now, when I upload the application (maps 'app', 'src' and 'web') and upload the database, change the config.php to the correct database credentials I issue the composer command (composer.phar -o install) to install the vendor dependencies.
Until this point everything works, Composer makes the 'vendor' map and installs the dependencies without errors. But when I visit the website it shows me the error:
Fatal error: Class 'WanaKo\Provider\Controller\HomeController' not found in /home/wanako/domains/wanako.net/app/app.php on line 37
What can I do to fix that error? I must add that the server is running DirectAdmin with PHP 5.5.16 and that I've made a symlink from 'public_html/' to 'web/'
The directory structure is:
/home/wanako/domains/wanako.net/
├── app
├── logs
├── public_ftp
│ └── incoming
├── public_html -> web/
├── src
│ ├── wanako
│ │ ├── provider
│ │ │ └── controller
│ │ └── repository
│ └── views
│ ├── errors
│ └── home
├── vendor
│ ├── composer
│ ├── doctrine
│ │ ├── common
│ │ └── dbal
│ ├── igorw
│ │ └── config-service-provider
│ ├── imagine
│ │ └── imagine
│ ├── ircmaxell
│ │ └── password-compat
│ ├── knplabs
│ │ └── repository-service-provider
│ ├── monolog
│ │ └── monolog
│ ├── neutron
│ │ └── silex-imagine-provider
│ ├── pimple
│ │ └── pimple
│ ├── psr
│ │ └── log
│ ├── silex
│ │ └── silex
│ ├── swiftmailer
│ │ └── swiftmailer
│ ├── symfony
│ │ ├── config
│ │ ├── debug
│ │ ├── event-dispatcher
│ │ ├── filesystem
│ │ ├── form
│ │ ├── http-foundation
│ │ ├── http-kernel
│ │ ├── icu
│ │ ├── intl
│ │ ├── locale
│ │ ├── options-resolver
│ │ ├── property-access
│ │ ├── routing
│ │ ├── security-core
│ │ ├── security-csrf
│ │ ├── translation
│ │ ├── twig-bridge
│ │ └── validator
│ └── twig
│ └── twig
└── web
├── css
├── font
├── images
└── js
composer.json
{
"name": "Wanako/Wakano.net",
"require": {
"silex/silex": "1.0.*#dev",
"twig/twig": ">=1.8,<2.0-dev",
"doctrine/dbal": "2.*",
"knplabs/repository-service-provider": "dev-master",
"symfony/twig-bridge": "~2.1",
"symfony/form": "~2.1",
"symfony/validator": "~2.1",
"symfony/config": "~2.1",
"symfony/translation": "~2.1",
"symfony/locale": "~2.1",
"monolog/monolog": ">=1.0.0",
"igorw/config-service-provider": "~1.1",
"swiftmailer/swiftmailer": ">=4.1.2,<4.2-dev",
"ircmaxell/password-compat": "dev-master",
"neutron/silex-imagine-provider": "~0.1"
},
"autoload": {
"psr-0": {
"WanaKo": "./src/"
}
}
}
At line 37 of app/app.php I've got:
$app->mount('/', new WanaKo\Provider\Controller\HomeController());
homecontroller.php (in the folder src/wanako/provider/controller/)
<?php
namespace WanaKo\Provider\Controller;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\Validator\Constraints as Assert;
class HomeController implements ControllerProviderInterface {
$controllers = $app['controllers_factory'];
// Bind sub-routes
$controllers->get('/', array($this, 'home'))->method('GET')->bind('home.news');
return $controllers;
}
public function home(Application $app) {
// STUFF
}
I've got no clue on this one. Is there something I did wrong? Wrong folder structure? Something I forgot? If anyone needs more info, just ask. Thanks for helping out!
I believe you have to name your folder structure and files in the correct case for psr0 to work correctly, like this:
src/WanaKo/Provider/Controller/HomeController.php
I have already installed cakephp verion 1.3 on root of domain for Application1.
Now i want to develop another music application, that i want to store in a sub-directory. Now i want to use latest cakephp version for this application.
I am new to cakephp, and donot want to use same cakephp core for both application. First root application was not developed by me.
Directory structure is a s follow.
ROOT
├── .htaccess
├── cake
│ ├── config
│ ├── console
│ ├── libs
│ ├── tests
├── app
│ │ ├── .htaccess
│ │ ├── libs
│ │ ├── vendors
│ │ ├── config
│ │ ├── plugins
│ │ ├── views
│ │ ├── models
│ │ ├── controllers
│ │ ├── temp
│ │ ├── WEBROOT
│ │ │ ├── .htaccess
├──music (this one i want to use for latest version cakephp installation).
I installed cakephp 2.5.2 in music directory, but unable to access this by www.example.com/music/
It redirect to first root application i.e. example.com/member/index.
In
├── app
│ │ ├── config
│ │ ├ ├──routes.php
I have this:
Router::connect('/', array('controller' => 'members', 'action' => 'index'));
If unable to understand what i want:
My Question:
How can i run two different cakephp version, one on root of the domain
and second in subdirectory (music).
If not possible i will use same version, but one application will be in music sub directory.
Both the versions should work fine, just make sure you have not written a htaaccess rule to redirect all incoming request to the first cakephp folder.