Class "App\Http\Controllers\settingsController\Settings" not found - laravel

web.php
<?php
use App\Http\Controllers\settingsController\seoController;
use App\Http\Controllers\settingsController\contactController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\generalController\generalRoutes;
use App\Http\Controllers\settingsController\usersController;
Route::controller(generalRoutes::class)->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/getNews', 'getNews');
});
Route::prefix('settings')->group(function () {
Route::controller(contactController::class)->group(function () {
Route::get('/contact', 'index')->name('contactIndex');
Route::post('/contact/update/general', 'generalContactUpdate')->name('generalSContactUpdate');
Route::post('/contact/update/html', 'staticHtmlUpdate')->name('staticHtmlUpdate');
});
});
contactController
<?php
namespace App\Http\Controllers\settingsController;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class contactController extends Controller
{
public function index(){
$data = Settings::find(1);
return view('settings.contact',compact('data'));
}
I wanted create contactController, I had this problem before
Class "App\Http\Controllers\settingsController\contactController" not found
enter image description here
I solve it but now it gives settingsController error
Class "App\Http\Controllers\settingsController\Settings" not found
Please help me))
I want create contactController but it gives settingsController problem

Add this on top of your web.php
Use App\Http\Controllers\settingsController\contactController.php;

Hey Just for clearing your doubts giving you some hint for this basic question.
If you want to use controller you can use it with the help of namespaces like below:
namespace App\Http\Controllers;
And if you want to fix this error Class "App\Http\Controllers\settingsController\Settings" not found
First, you need to specify the modal from where you want the data like this:
use App\Models\Settings;
After that If you want to retrieve data form that modal you can simply do this:
$data = Settings::find($id);
Hope it will help you for basic understanding the usage of controllers and modals in laravel. If you are still struggling with the issue below doc link will surely help you. Keep Learning.
https://laravel.com/docs/9.x/controllers#basic-controllers

Related

Class App\Http\Controllers\CategoriesController does not exist

hi m trying to get view of page but it says: Class App\Http\Controllers\CategoriesController does not exist
pic of folder structure https://ibb.co/gMBvwDJ
Route:
Route::match(['get','post'],'/admin/categories/index','CategoriesController#Category');
controller:
public function index()
{
return view('admin.categories.index');
}
First of all you use a wrong definition of the route match, so try this:
Route::match(['get','post'], 'CategoriesController#index');
and second, make sure that in your CategoriesController you use the right namespace, which should be:
namespace App\Http\Controllers;
at the very top of the class.
It gives you that error because the controller couldn't find the class you are calling so in order to fix the problem, in the top of your controller add
use App{ModalName};
for example if your model for this is called categories,
use App\categories;
as well as add
namespace App\Http\Controllers;
Please make sure your controller is placed in below directory structure or else you have to fix the namespace problem

What is wrong with my route or controller for listing resources belonging to a given language identifier?

I am trying (and failing!) to generate a list of factsheets from the database that have been tagged according to language (English or Vietnamese). I have a route in which the variable can be either "en" or "vn" being passed to the index function in my controller
Route::get('/pest/{id}', 'api\FactsheetsController#index');
My controller is currently as...
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
class FactsheetsController extends Controller
{
public function index($lang)
{
$factsheets = DB::table("factsheetcontents as fsc")
->where('fsc.lang',$lang)
->select('fsc.title', 'fsc.id', 'fsc.shortimg')
->get();
return $factsheets;
}
I receive an empty response ([]) for my efforts. What am I doing wrong here?
Thanks, Tom

Class 'Illuminate\Support\Facade\Mail' not found in laravel 5

I get this error message while trying to send email (Class 'Illuminate\Support\Facade\Mail' not found).
in the controller, I have included 'use Illuminate\Support\Facade\Mail;' in the begining of the controller class (PostsController) and in the store function (of the controller), I have this
Mail::send('welcome_email', $data, function ($message) {
$message->from('walegbenga807#gmail.com', 'Coa Blog');
$message->to('nigeriawonderboy#gmail.com')->subject('There is a new post!');
});
return redirect('/')->with('status', 'ticket created');
Try to change the
use Illuminate\Support\Facade\Mail
to
use Illuminate\Support\Facades\Mail;
Since it's a facade, just add this to the top of the class:
use Mail;
Or use full namespace when using the facade:
\Mail::send
Try to use 'use Illuminate\Support\Facades\Mail';
Actually there is no Facade package, but Facades.
Laravel don't know what is "Facade" but try adding s for Facade word.
Try to use
use Illuminate\Support\Facades\Mail;
For more about facades refer:
Facades

Dynamic Routes not found

I am having trouble getting dynamic routes to work in Laravel 4
Routes
Route::any('/browse/{$id}', 'BrowseController#showProfile');
Controller
<?php
class BrowseController extends BaseController {
public function showProfile($id)
{
return $car_id;
}
}
When I go to http://localhost:8000/browse/10018
I receive a not found error
Any Idea what is wrong? Sorry I am new to Laravel
You don't need a $ in the variable name in your route. Try using
Route::any('/browse/{id}', 'BrowseController#showProfile');
Also, you should add validation to only allow numbers:
Route::any('/browse/{id}', 'BrowseController#showProfile')->where('id', '\d+');
The problem is in {$id}, try only {id}

How do you change the page name for Paginator?

Current Paginator is using ?page=N, but I want to use something else. How can I change so it's ?sida=N instead?
I've looked at Illuminate\Pagination\Environment and there is a method (setPageName()) there to change it (I assume), but how do you use it?
In the Paginator class there is a method the change the base url (setBaseUrl()) in the Environment class, but there is no method for setting a page name. Do I really need to extend the Paginator class just to be able to change the page name?
Just came across this same issue for 5.1 and you can pass the page name like this:
Post::paginate(1, ['*'], 'new-page-name');
Just like you said you can use the setPageName method:
Paginator::setPageName('sida');
You can place that in app/start/global.php.
Well that didnt work for me in laravel 5 , in laravel 5 you will need to do more extra work by overriding the PaginationServiceProvider because the queryName "page" was hardcoded in there , so first create your new PaginationServiceProvider in /app/providers ,This was mine
<?php
namespace App\Providers;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider as ServiceProvider;
class PaginationServiceProvider extends ServiceProvider {
//boot
public function boot()
{
Paginator::currentPageResolver(function()
{
return $this->app['request']->input('p');
});
}//end boot
public function register()
{
//
}
}
Then in your controllers you can do this
$users = User::where("status","=",1)
->paginate(5)
->setPageName("p");

Resources