I'm new to programming. I've been using codeigniter, and Laravel seemed a classy framework to learn.
I have this routes:
Route::get('slider', 'AdminController#getSlider');
Route::get('/', 'AdminController#getSlider');
and my controller:
class AdminController extends BaseController {
public function getSlider(){
return View::make('list', array('section' => 'slider_home'));
}
}
"public/" works great. "public/slider" spits NotFoundHttpException.
If there is some data that i should add please tell me.
Thanks, and excuse my english.
UPDATE:
I got it wrong. The correct URL was "public/index.php/slider". Now I need to modify the .htacces to change that.
Try this Route :
Route::controller('','AdminController');
Controller :
class AdminController extends BaseController {
public function getIndex(){
return View::make('list', array('section' => 'slider_home'));
}
public function getSlider(){
return View::make('list', array('section' => 'slider_home'));
}
}
ok you can use public/ and public/slider
Related
I cant seem to get my edit function to work in my resourceful controller. This is my controller:
class UserController extends Controller{
public function index()
{
return view('testindex');
}
public function test(){
return 'test';
}
public function edit(User $user){
return 'test2';
}
public function create(){
return 'test3';
}
}
And my routes:
Route::post('test','UserController#test');
Route::resource('/','UserController');
Which mean that edit should be in the resource controller.
Create works but edit isn't, it gives me a
NotFoundHttpException
This is the form:
Edit
And yes, the variable $id works and is showing in the url.
What am I doing wrong here?
This is because you're not naming the resource i.e.
Route::resource('user', 'UserController');
To get around this you will need to change you route to be:
Route::resource('/', 'UserController', ['parameters' => [
'' => 'user'
]]);
(The above will allow you to keep your urls the same).
Please note that you will have to keep this Route at the bottom of your file.
Hope this helps!
I am fresher in cakephp. For my current project, I am using CakePHP skeleton app. Everything going fine. But when I am creating new controller for admin panel then it showing this message Did you really think you are allowed to see that?. Someone please help me.
I am showing my codes below:
Route:
Router::prefix('admin', function ($routes) {
// Other routes are here.
$routes->connect('/sections', ['controller' => 'Sections', 'action' =>'index']);
}
SectionsController.php
<?php
namespace App\Controller\Admin;
use App\Controller\AppController;
class SectionsController extends AppController {
public function index() {
echo "I am for sections page";
}
}
This controller is locate in src\Controller\Admin folder
Below is my error message.
probably this would be the solution.
use Cake\Event\Event;
class YourController extends AppController
{
public function beforeFilter(Event $event)
{
parent::beforeFilter($event);
$this->Auth->allow('index');
}
}
Laravel 5.1
This seems strange to me:
Route::group([
'middleware'=>['auth','acl:view activity dashboard'],
'prefix' => 'api/v1'
], function(){
Route::controller('investment-transactions', 'Api\V1\Investments\InvestmentTransactionsController');
Route::controller('investment-transactions/{offeringID}', 'Api\V1\Investments\InvestmentTransactionsController#getTransactionsForOffering');
});
Seems pretty normal to me, the controller:
namespace App\Http\Controllers\Api\V1\Investments;
use App\Brewster\Models\Company;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class InvestmentTransactionsController extends Controller {
public function __construct() {
}
public function getIndex() {
echo 'Here';
}
public function getTransactionsForOffering($offeringID) {
echo $offeringID;
}
}
Ok so the action and the controller do exit, but when I run: php artisan routes:list I get:
[ReflectionException]
Class App\Http\Controllers\Api\V1\Investments\InvestmentTransactionsController#getTransactionsForOffering does not exist
Well obviously App\Http\Controllers\Api\V1\Investments\InvestmentTransactionsController#getTransactionsForOffering is not a class, how ever: App\Http\Controllers\Api\V1\Investments\InvestmentTransactionsController is and getTransactionsForOffering is an action.
Whats going on?
I believe your problem is in the routes.php we can use controllers as follows
Route::get('investment-transactions', 'InvestmentTransactionsController#index');
Route::get('investment-transactions/{offeringID}', 'InvestmentTransactionsController#getTransactionsForOffering');
By default, our controllers are stored in App/http/controllers folder and laravel know it.
I believe you only need to reference the Class like so:
Route::controller('investment-transactions','InvestmentTransactionsController#Index'); //make sure you create a function for the index
Route::controller('investment-transactions/{offeringID}', 'InvestmentTransactionsController#getTransactionsForOffering');
Assuming you need to show a view for the route investment-transactions create the following function in your controller:
public function index()
{
return view('name-of-your-view-file');
}
I know laravel 5 isnt out yet and in development stages but I have been playing around with it to try and understand how it works. Using the HomeController, i added another method called contact and when i try to visit it via the browser it just show a 404 page. What am i doing wrong? By default routes are disabled and everything is passed through the controllers.
http://domain.com/home/contact
<?php namespace App\Http\Controllers;
use Illuminate\Routing\Controller;
class HomeController extends Controller
{
public function index()
{
$data = array(
'fname' => 'sarmen',
'lname' => 'b'
);
return view('pages.home')->with('data', $data);
}
public function contact()
{
return 'contact us';
}
}
in
app/Providers/RouteServiceProviders.php
this line
require app_path('Http/routes.php');
is commented out. So i just uncommented it and put this into my routes.php
$router->get('contact', 'HomeController#contact');
and it still doesn't work.
You should put the solution here and also a link for reference, not only the link:
From Laracast forum:
You need to specify the full path:
App\Http\Controllers\HomeController
Either that, or add a namespace to the RouteServiceProvider section, where you require routes.php - like this:
public function map(Router $router) {
$router->group(['namespace' => $this->rootUrlNamespace],
function() use ($router) {
require app_path('Http/routes.php');
});
}
found the solution thanks to jeffrey way
https://laracasts.com/discuss/channels/general-discussion/controller-class-not-found
I am trying to run a sample example using Laravel 4 and i am getting errors like, class not found. Can someone help me out here?
controller
file name : authors.php
<?php
class Authors extends BaseController {
public $restful = true;
public function get_index() {
return View::make('authors.index');
}
}
?>
routes.php
Route::get('authors', array('uses'=>'authors#index'));
Views/authors/index.php
<h1> First program in Laravel 4 </h1>
Fitst of all your authors!=Authors, so make sure of your conyroller name in the Route.
And if you want RESTful controller then you can define your route like Route::controller('baseURI','ControllerName'),
Laravel allows you to easily define a single route to handle every action in a controller using simple, REST naming conventions. First, define the route using the Route::controller method..
To know more check restful-controllers
In your example you have to rename your get_index method to getIndex as L4 is camelCase
//AuthorsController.php
class AuthorsController extends BaseController {
public $restful = true;
public function getIndex() {
return View::make('authors.index');
}
}
//route.php
Route::controller('authors', 'AuthorsController');