Laravel custom controller not found when changing the controller directory - laravel-controller

When changing the controller directory location like so:
Route::group([
'prefix' => 'report',
'middleware' => 'auth',
], function() {
Route::get('/summary','IOS\ReportController#index');
});
It returns an error message:
Error
Class 'App\Http\Controllers\IOS\Controller' not found
But it's working perfectly the below way:
Route::group([
'prefix' => 'report',
'middleware' => 'auth',
], function() {
Route::get('/summary','ReportController#index');
});
After changing directory location, i try to composer dump-autoload but it's still getting error.

every Controller on laravel should extends the base laravel Controller
the base controller is in this path: App\Http\Controllers
so when you create a controller on another folder, the created controller wants to extend from the base controller but can not find it in folder
so you should do this on ReportController
namespace App\Http\Controllers\IOS; //namespace of your controller
use App\Http\Controllers\Controller; //the path of base Controller
class ReportController extends Controller //your controller extends from base controller

Related

aurelia/skeleton-plugin cant run test on custum element

i have created an aurelia plugin using the skelton-plugin https://github.com/aurelia/skeleton-plugin i am now looking at writing unit tests for it.
i am stuggling to get a unit test running for a custom element ive added to the project. i started with the 'testing a custom element' example from http://aurelia.io/hub.html#/doc/article/aurelia/testing/latest/testing-components/3
template:
<template>
<div class="firstName">${firstName}</div>
</template>
vm
import {bindable} from 'aurelia-framework';
export class MyComponent {
#bindable firstName;
}
i added this to the src folder.
my test code is
import {StageComponent} from 'aurelia-testing';
import {bootstrap} from 'aurelia-bootstrapper';
describe('MyComponent', () => {
let component;
beforeEach(() => {
component = StageComponent
.withResources('my-component')
.inView('<my-component first-name.bind="firstName"></my-component>')
.boundTo({ firstName: 'Bob' });
});
it('should render first name', done => {
component.create(bootstrap).then(() => {
const nameElement = document.querySelector('.firstName');
expect(nameElement.innerHTML).toBe('Bob');
done();
}).catch(e => { console.log(e.toString()) });
});
afterEach(() => {
component.dispose();
});
});
i jspm installed aurelia-bootstrapper and aurelia-testing to get it running.
im now getting the error
Error{stack: '(SystemJS) XHR error (404 Not Found) loading http://localhost:9876/base/my-component.js
so it looks like karma cant find my component. i checked the karma.config file and the jspm loadFiles: ['test/setup.js', 'test/unit/**/*.js'], looks correct.
has any one run into a similar issue?
solved the issue.
in karma.config.js file needed to change
serveFiles: ['src//.']
to
serveFiles: ['src//*.js', 'src/**/*.html']

How to make POST call using FOSRestBundle

I am trying to setup a RESTFUL web service using FOSRestBunble, but I have some problem making POST calls, here's my setup:
app/config/routing.yml
rest:
type: rest
resource: "routing_rest.yml"
prefix: /api
app/config/routing_rest.yml
Rest_User:
type: rest
resource: "#AppBundle/Resources/config/routing_rest.yml"
AppBundle/Resources/config/routing_rest.yml
rest_application:
type: rest
resource: "AppBundle:Rest"
name_prefix: api_
AppBundle/Controller/RestController.php
class RestController extends FOSRestController
{
public function testrestAction(Request $request)
{
$r = [
'is' => 'TEST'
];
return $r;
}
public function getArticleAction()
{
$r = [
'is' => 'GET'
];
return $r;
}
public function postArticleAction()
{
$r = [
'is' => 'POST'
];
return $r;
}
}
I also made PUT and DELETE test methods. so when I do some test call
GET /api/testrest
{
"is": "TEST"
}
GET /api/article
{
"is": "GET"
}
POST /api/article
No route found for "POST /api/article": Method Not Allowed (Allow: GET, HEAD) (405 Method Not Allowed)
PUT and DELETE are also fine. Am I missing some configuration?
second problem: if I make a API folder inside Controller folder, I change the namespace for RestController to "namespace AppBundle\Controller\API;" and I update "AppBundle/Resources/config/routing_rest.yml" to
resource: "AppBundle:API:Rest"
then I got this message:
Can't locate "AppBundle:API:Rest" controller in /var/www/ws/app/config/routing_rest.yml (which is being imported from "/var/www/ws/app/config/routing.yml").
any help appreciated
1-option, run app/console debug:router (or bin/console debug:router if v > 2.8), to list generated routes;
2-option, add RouteResource annotation to class (eg. article), rename postArticleAction to postAction and check POST /api/articles is responding or not;
3-option, add article url explicitly with #POST annotation, eg. /** #Post("article") */

Ionic 2 : Moving config properties into the bootstrap

Before beta.8 version, I have a working service which acts as my HTTP service.
#Page({
templateUrl: 'build/pages/log-in/log-in.html',
providers: [httpService]
})
...
this.httpService.testService("VariablesToPass").subscribe(
data => {this.results = data.results; console.log(data);},
//err => this.logError(err),
err => console.log(err),
() => console.log('Invoked Login Service Complete')
);
After the new version, configs have to move into the bootstrap, thus in my js i implemented the following :
#Component({
templateUrl: 'build/pages/log-in/log-in.html'
})
export class LoginPage {
...
}
ionicBootstrap(LoginPage, [httpService], {});
in which throws me errors like:
Using
ionicBootstrap(LoginPage, [httpService], {});
or
ionicBootstrap(LoginPage, [httpService]);
gives the same error result.
ionicBootstrap must be used only in your former #App, not in a former #Page, inject httpService there, not in LoginPage.
In your LoginPage leave the provider registration. Also, beware of your naming convention, it doesn't look right, you are using the same name for the service and its instance. It should be like this:
#Component({
templateUrl: 'build/pages/log-in/log-in.html',
providers: [HttpService]
})
class LoginPage {
constructor ( private httpService : HttpService) {}
}
also, it's beta 8, not RC

How to call parent's method when requiring child class?

I have the following hierarchy:
class BaseController
validateCloverToken: ->
console.log 123
module.exports = new class RetailersController extends BaseController
getAll: (req, reply) ->
#validateCloverToken()
When I try to call RetailersController in another file:
RetailersController = require("../controllers/retailers")
RetailersController.getAll()
I get the following exception:
TypeError: Uncaught error: this.validateCloverToken is not a function
Any ideas how to fix this?
I am using it within a HapiJS route:
{
method: "GET"
path: "/retailers"
handler: RetailersController.getAll
config:
auth:
strategy: "jwt"
scope: ["a"]
description: "Get a list of all retailers"
tags: ["api"]
}
The code does not work here with HapiJS. "this" was the HapiJS context. When I use a fat arrow for the getAll function everything works fine.
It should look like:
getAll: (req, reply) =>
#validateCloverToken()

Ignored attempt to bind route (/Nindex) to unkown controller :: usercontroller.hi

I'm trying to bind a route to my usercontroller's action hi, it renders the view.
This is in my routes.js
'get /Nindex': {
controller: 'UserController.hi'
},
and this is in my UserController.js under /api/controllers
module.exports = {
hi: function (req, res) {
res.view('/Nindex');
}
};
I'm getting the error mentioned in the title on my command prompt after running sails lift
You're combining two methods of declaring the route into one. Use either of:
'get /Nindex': 'UserController.hi',
or
'get /Nindex': {
controller: 'UserController',
action : 'hi'
},