How to access controller from vendor in http\controller in Laravel? - laravel

I have tried using
$data = BasicFunctions::checkEmailExists('emailaddress', 'Modal_name');
I am using my own package https://packagist.org/packages/jainam/basicfunctions
It is giving error that Class vendor\jainam\basicfunctions\src\BasicFunctions does not exist
Can anyone know how to use this?
I am adding that file using use BasicFunctions;

Open your plugin's composer.json file and change
"autoload": {
"psr-4": {
"jainam\\BasicFunctions\\": "src/"
}
}
to
"autoload": {
"psr-4": {
"Jainam\\": "src/"
}
}
NOTE: "Jainam\\": "src/" here is the namespace, so you will end up writing use Jainam\BasicFunctions in your code.
Then install the plugin and run composer dump-autoload.
To test this now, you can directly edit the composer.json file inside vendor folder and run composer dump-autoload in your project

Related

nohoist with workspaces still hoisting

Inside my Monorepo I have one packages in which I want all the dependencies inside its node_modules.
But whatever I do, it's node_modules remains empty.
So, for the purpose of my question I was able to reproduce the issue with the following setup
/
package.json
lerna.json
node_modules
packages/
A/
node_modules
package.json
index.ts
B/
node_modules
package.json
index.ts
I've created a repo for this!
Main package.json
{
"name": "A-B-test",
"private": true,
"workspaces": {
"packages": ["packages/*"],
"nohoist": [ "**/B" ]
},
...
"devDependencies": {
"lerna": "^3.13.4"
}
}
B/package.json looks like
{
"name": "#scaljeri/B",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"angular": "^1.7.8"
},
"devDependencies": {
"browserify": "^16.2.3",
"typescript": "^3.5.2"
}
}
Now when I run yarn in the root of the project, all dependencies are installed in the root node_modules.
yarn version: 1.16.0
node: 12.4.0
Any suggestions what might be the problem?
In my experience, it has been necessary to doubly specify each package in the following manner:
{
"nohoist": [
"**/B",
"**/B/**",
"**/C",
"**/C/**"
]
}
In addition, I have found it necessary to delete all existing node_modules folders after modifying the nohoist settings. So, if your projects are in packages, and you are in your project directory, you can delete all of those node_modules folders like this:
# delete node_modules on linux
rm -rf ./packages/*/node_modules
rm -rf ./node_modules
# install again
yarn install --check-files
I tried a few options but the only one that finally worked for me was specifying the nohoist option in the child package. No need to specify anything at the root level.
So my package.json in B package is:
{
...
"workspaces": {
"nohoist": ["**"]
},
...
}
Applying the nohoist to the child package's package.json did it for me.
"workspaces": {
"nohoist": [
"*react-native*",
"*react-native*/**"
]
},
If you want to exclude package B node modules from hoisting you can do that in you package.json:
"workspaces": {
"nohoist": [
"**/B",
"**/B/**"
]
},
after that remove node_modules and yarn.lock and run yarn install again now you should see packages/B/node_modules not being hoisted to the top level of the project

How to set package.json configurations using kotlin-frontend-plugin

I want the auto-generated package.json to be configured in a way that it points to the Kotlin generated JavaScript file. This is my current gradle configuration:
apply plugin: 'kotlin-platform-js'
apply from: "$project.rootDir/gradle/deploy.gradle"
dependencies {
expectedBy project(":")
// Compile/implementation dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
}
apply plugin: 'org.jetbrains.kotlin.frontend'
compileKotlin2Js {
kotlinOptions.metaInfo = true
kotlinOptions.sourceMap = true
kotlinOptions.moduleKind = 'commonjs'
}
kotlinFrontend {
sourceMaps = true
npm {
dependency("kotlin")
replaceVersion("kotlin-js-library", "1.1.0")
}
define "PRODUCTION", true
webpackBundle {
bundleName = "${project.name}"
sourceMapEnabled = true
}
}
This outputs both a myProject.js file located in $project.builDir.path/classes/nain which is what I hoped would be reflected in the generated package.json file. But the outputted package.json file (located in the project's build directory) is like this:
{
"name": "myProject",
"version": "1.2.0-10-SNAPSHOT",
"description": "simple description",
"main": "myProject",
"dependencies": {
"kotlin": "*"
},
"devDependencies": {
"webpack": "*",
"webpack-dev-server": "*",
"source-map-loader": "*",
"karma": "*",
"qunitjs": "1.23.1",
"karma-qunit": "*",
"karma-sourcemap-loader": "*",
"karma-phantomjs-launcher": "*",
"phantomjs-prebuilt": "*",
"karma-webpack": "*"
}
}
The problem is this, the "main" attribute in the package.json does not point to the bundle file located in classes/main/myProject.js. I tried looking through the documentation to find how to set the main attribute to the to a specific directory and js file but could not find it. I can only change the name by setting bundleName property in webpackBundle portion of the gradle file. Thanks for the help in advance!
So I found a work around to be able to use gradle to publish to npm. I added the following bit to my code:
apply plugin: "com.moowork.node"
//Must copy the output javascript file
//to the location that the package.json expects it to be
//This is semi-workaround since I have not found a way to
//configure the outputted package.json file
task copyJSFile(type: Copy){
from "$project.buildDir.path/classes/main/"
into "${project.buildDir}"
include "*.js"
}
//We publish our project to npm
task npmPublish(dependsOn: copyJSFile, type: NpmTask) {
description = "publishes the project to npm"
workingDir = file("${project.buildDir}")
args = ['publish']
}
What this does is copy the outputted JavaScript generated files to a place where the package.json is configured when you call the npmPublish gradle task.

Composer doesn't create symbolic link to bin script

I have problem with composer to generate symbolic link.
I have script in ./bin/my-script which code looks like:
#!/usr/bin/php
<?php echo 'Hello World!'; ?>
I have added config in to package composer.json (not in to main project)
"bin": ["bin/my-script"]
When updating composer in main project my package is installing fine.
However composer not creates symbolic link to my bin script in ./vendor/bin
What I'm doing wrong?
OK I found the problem.
As I pull from local repository instead composer packages
I had to add below line in to repositories settings in my main project.
"repositories": [
{
"type": "package",
"package": {
"name": "200mph/m-commander",
"version": "dev-master",
"source": {
"url": "/home/wojtek/m-commander",
"type": "git",
"reference": "develop"
},
"bin": ["bin/m-commander"],
"autoload": {
"psr-4" : {
"mcommander\\" : "src/",
"examples\\mcommander\\" : "examples/"
}
}
}
}
]
Did you checked this link https://getcomposer.org/doc/articles/vendor-binaries.md
I think your problem related with following subject :
What happens when Composer is run on a composer.json that defines
vendor binaries?#
For the binaries that a package defines directly, nothing happens.
What happens when Composer is run on a composer.json that has
dependencies with vendor binaries listed?#
Composer looks for the binaries defined in all of the dependencies. A
symlink is created from each dependency's binaries to vendor/bin.

Composer local packages

I can't get composer to work properly with local packages.
package A:
{
"name": "package/A",
"repositories": [
{
"type": "vcs",
"url": "../B"
}
],
"require": {
"package/B": "dev-master"
}
}
package B:
{
"name": "package/B",
"repositories": [
{
"type": "vcs",
"url": "../C"
}
],
"require": {
"package/C": "dev-master"
}
}
package C:
{
"name": "package/C",
}
Now installing package B works fine and it resolves the package C properly.
Installing package A fails because it can not resolve the package C from the package B, which is the only dependency of package A.
I couldn't find anything about this #google, it looks like composer can't handle that kind of complexity in local packages. Hopefully I'm wrong.
Here is a small illustration for better understanding of this problem.
Composer doesn't load local repos recursively.
1) You might declare dependencies for B and C in A. You have to redefine the dependencies in your composer.json. Here, this will add some more require and repository defines to composer.json of A.
2) Or you might setup a local Satis proxy, which serves your private packages.
Private or public publishing of the dependencies will resolve the situation.

Composer does not find dependencies of vcs repository

i've got a strange problem ...
project-a is my main project.
project-b is my library, checked in to subversion
composer.json of project-b
{
"name": "fragger/baseclasses",
"version" : "0.0.1-dev",
"description": "Baseclasses and Interfaces",
"require": {
"silex/silex": "1.0.x-dev",
"3rd-party/smarty": "3.*",
"swiftmailer/swiftmailer": "4.2-dev"
},
"autoload": {
"psr-0": { "baseclasses": "src/" }
}
}
and composer.json of project-b
{
"repositories" : [
{
"type": "vcs",
"url" : "svn+ssh://....."
}
],
"require": {
"fragger/baseclasses": ">=0.0.1-dev"
}
}
output of install command
php composer.phar install
Loading composer repositories with package information
Installing dependencies
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for fragger/baseclasses >=0.0.1-dev -> satisfiable by fragger/baseclasses dev-trunk.
- fragger/baseclasses dev-trunk requires silex/silex 1.0.x-dev -> no matching package found.
But a composer install in project a alone, works fine
You can find detailed information about the packages on packgist, for example for Silex, but it seems, that all of your dependencies have invalid version strings.
Instead of "silex/silex": "1.0.x-dev" it must be named "silex/silex": "1.0.*#dev". There is no branch for 1.0.x and the correct version string for a branch would be dev-branchname anyway ;)

Resources