I have deleted the main controller Laravel by path: App\Http\Controllers\Controller.php;
All new controllers extent this controller:
class MainController extends Controller
{
}
How to generate a core controller in Laravel again?
I think you can't regenerate core Controller class via command neither artisan nor composer . You have to copy this from github or another project.
I don't think either you are able to regenerate it. But you can get a copy of the content here
Related
I want use a variable from my database to set a folder for custom views.
"class AppServiceProvider extends ServiceProvider"
$ActiveProject = ThemeConfig::where('module_type',"project")->where('active',"1")->first()->file;
After this, I get an active project name (like Nshop), and I want to set it in:
public function register()
{
$this->app['view']->addNamespace('Projects', base_path() . '/Projects/'.$ActiveProject.'/Views');
}
But I get an error.
How can I accomplish this task?
Using ORM Models in the AppServiceProvider doesn't work. This file is part of the boot process of Laravel where your models are not loaded yet. But you can rely on functions that are part of the Laravel core concept.
$ActiveProject = ThemeConfig::where('module_type',"project")->where('active',"1")->first()->file;
Becomes
$ActiveProject = \DB::table('theme_configs')->where('module_type',"project")->where('active',"1")->first()->file;
I am using Laravel 5.4.16 While using make method of View class i am getting undefined method error.
public function Index()
{
return View::make('stats');
}
Try to add this to the top of the class:
use View;
If it doesn't work then it looks like you didn't install the project. You need to run composer install or composer update command which will download and install all dependencies into the vendor directory.
Another thing to check is config/app.php should have this line:
'View' => Illuminate\Support\Facades\View::class,
Alternatively, you could use helper:
return view('stats');
But it will work only if porject is installed properly.
return view('path.to.your.directory');
You are receiving this error because make() method doesn't exist anywhere in your code. If you want to go from controller to view you can use simply:
public function Index() {
return view('stats');
}
It will go to your status blade view by accessing your url request.
Just use Facade instead. Check how it works and then check what is wrong with View first. And I hope you are not using another template engine as Twig for example, cause if yes then you have definitely use Facade or check how the View factory is working, I think it requires template engine in the constructor ...
Just use use Illuminate\Support\Facades\View;
You can try to use it:
return view('stats');
I'm very new to the Laravel framework and am trying to load a simple controller in my browser to slowly get the hang of things.
I have a file that's titled users.php inside of the the laravel/app/controllers/ folder and it looks like this:
class UsersController extends BaseController
{
public $restful = true;
public function action_index()
{
echo 'hi';
}
}
In the routes.php file, I have
Route::get('users', 'UsersController#index');
But, when I go to
http://localhost:8888/laravel/public/users
I'm greeted with a message that says "ReflectionException
Class UsersController does not exist"
I'm not sure if this is because I didn't install the mcrypt extension of PHP. But, when I checked the php.ini file on MAMP, it said that it was enabled. Upon entering
which PHP
in my terminal, it said /usr/bin/php. So, it might not be using the correct version of PHP.
I'm not entirely sure if this is a routes problem or if it's stemming from an absence of a vital PHP extension.
Thanks a bunch!
You need to use the Route::controller method to reference your Controller:
Route::controller('test', 'TestController');
...and rename your file (as Cryode mentions ) to be TestController.php.
Note - if you want to use the filename as test.php, then you will need to use composer to update the autoload settings.
Finally, the format of names for Controller methods changed in Laravel 4, try renaming the method
public function action_index() {}
to be
public function getIndex() {}
the get represents a HTTP GET request... the same applies for post (HTTP POST) and any (GET or POST.. )
I'm not familiar with that part of Laravel's source, so I'm not entirely certain that this is the issue, but your controller file name should match the controller class name, including capitalization.
So users.php should be UsersController.php. Now, when I do this myself on purpose, I get a "No such file or directory" error on an include() call, so that's why I'm not certain that's the sole cause of your problem. But it may be a start.
I'm getting an error that a class (a controller) is not being found. Thing is, it is found in my local development environment. I created the controller with php artisan controller:make CssController --path=app/controllers/home.
I renamed the class (not the file) Home_CssController. I added the route:
Route::get('home/css-php', 'Home_CssController#index');
to my routes file. Everything works fine in my local environment. I did forget to run composer dump-autoload but there were no issues with viewing the controller/view in my local environment. I've uploaded everything to the live server, but I'm getting the error:
Class Home_CssController does not exist
I've uploaded the controller, the routes file and the view multiple times. But I still get the error. Is it because the controller wasn't registered with composer? I've since registered it, but am not sure what I need to upload to the server. I've uploaded both the config and bootstrap folders. What do I need to do to get the controller/view to be found? This is Laravel 4.
If the controller isn't in the app/controllers folder, then it will need to be namespaced (unless you want to continue using your autoload.php trick).
Namespace Home_CssController to Home.
<?php namespace Home;
class CssController extends \BaseController
Then, you can use it in your routes:
Route::get('home/css-php', 'Home\CssController#index');
I'm trying to integrate Google Calendar in my php application (I use CodeIgniter for this).
I have a problem with my controller calendar.php.
<?php
session_start();
Class Calendar extends Controller {
function Calendar(){
echo 'start';
parent::Controller();
echo 'okkkkkkkk';
require_once '/home/me/framework/ZendGdata/library/Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
}
but there is a problem with parent::Controller() because 'okkkkkk' is not printed.
Could anyone help me please?
Change
parent::Controller();
to
parent::__construct();
parent::Controller() doesn't work in CI because as of CI 2.1.2, the constructors are declared using PHP's __construct() method.
As a sidenote, it seems you are using an older version of CI. CI 2.o onwards, the base controller class is called CI_Controller as opposed to just Controller. You should look into updating your project by replacing the system folder.
You can find the full working code in this following link https://github.com/omerkamcili/ci_google_calendar_api.
After down loading the code create your service account, OAuth client Id's in the following link http://console.developers.google.com.
Then replace the client_id,client_secret,redirect_uri's in your project file in the following path -> /project_folder/application/config/client_secret_846685841138-t0a5b9d2i655e7km54md8j440jcg5rr5.apps.googleusercontent.com.json file
Finally download and replace the google-api-php-client in the following file path /project_folder/application/third_party/google-api-php-client