Undefined Variable Request in Laravel 5 - laravel-5

I am having issues it says Request is undefined same goes for DB.
public function edit(Request $request,$id) {
$name = $request->input('stud_name');
DB::update('update student set name = ? where id = ?',[$name,$id]);
echo "Record updated successfully.<br/>";
echo 'Click Here to go back.';
}

Looks like you're missing use statements that tell your script where to find these. Add
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
in your file after namespace ...

Related

Type error: ReflectionFunction::__construct() expects parameter 1 to be string, array given

I am new to Laravel. I am getting this Type Error when I change the following routings as below mentioned way.
My previous routing is as below.
web.php
Route::get('/add-teams',[
'as'=>'teams.add',
'uses'=>'TeamsController#addTeams'
]);
It works fine.
But I need to change that as this.
<?php
use App\Http\Controllers\TeamsController;
Route::get('/add-teams', [TeamsController::class, 'addTeams'])->name("teams.add");
Then this error appears. "Type error: ReflectionFunction::__construct() expects parameter 1 to be string, array given"
Please help me to solve this.
TeamsController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Teams;
class TeamsController extends Controller
{
public function saveTeams(Request $request){
$team=new Teams();
$team->team_name=$request->team_name;
$team->description=$request->description;
$team->save();
return back()->with('team_added','Team added successfuly!');
}
}

Moving project online broke laravel controller

That's my route:
Route::group(['prefix' => 'admin', 'middleware'=>['auth','role:admin']], function () {
Route::get('/co2index', 'UserController#adminCo2Index');
}
This is the controller method that fails:
<?php
namespace App\Http\Controllers;
use App\Http\Impl\ReferentManager;
use App\Http\Impl\RoleManager;
use App\Http\Impl\UserManager;
use App\Http\Impl\ValidationRulesManager;
use App\Models\User;
use App\Notifications\UserActivatedNotification;
use App\Models\Vendita;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Referent;
use App\Models\Ddt;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use Illuminate\Support\Facades\Session;
class UserController extends Controller
{
public function adminCo2Index()
{
$search = \Request::get('search'); //<-- we use global request to get the param of URI
$companies = User::where('name', 'like', '%' . $search . '%')->orderBy('name')
->paginate(10);
$ddts_count = DB::table('ddts')
->select('company_id', DB::raw('count(*) as total'))
->groupBy('company_id')
->get();
if ($companies && $ddts_count) {
return view('administration.co2Index')->with('companies', $companies)->with('ddts_count', $ddts_count);
} else {
return view('administration.co2Index')->with('companies', null)->with('ddts_count', null);
}
}
}
on my online server if I try to visit:
mysite.com/admin/co2index
it returns:
BadMethodCallException Method [adminCo2Index] does not exist. in
Controller.php line 82:
On localhost it works! Also, I have other methods on UserController class that work even online without any problem!
If I put 'null' on $companies or $ddts_count the correct empty view is loaded on localhost. If I do the same thing online I have still the same error!
If I put a dd('ciao') on the top of the method the error is still showed and no message on front end...
This looks very strange to me! I can't see any typos... thanks for the help!
hit this command
composer dump-autoload

DOM/PDF error - Non-static method Barryvdh\DomPDF\PDF::download() should not be called statically

My Controller is this:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Barryvdh\DomPDF\Facade as PDF;
class PrintPDF extends Controller
{
public function print(){
$details =['title' => 'test'];
$pdf = PDF::loadView('textDoc', $details);
return $pdf::download('this.pdf');
}
}
My routes
Route::get('/print', 'PrintPDF#print');
when accessing localhost/print I get an error
Non-static method Barryvdh\DomPDF\PDF::download() should not be called
statically
I followed the install instructions on their site. I have tried to change my controller adding use PDF, instead of use Barryvdh\DomPDF\Facade as PDF; Yet the error persists
This happens because you are namespacing the wrong PDF class.
You are namespacing Barryvdh\DomPDF\PDF and try to use this class as "Facade" which is wrong.
To solve your problem
Set namespace to the facade:
use Barryvdh\DomPDF\Facade as PDF;
Function Should be like this
$details =['title' => 'test'];
$pdf = PDF::loadView('Your view path', $details);
You can download directly using download method
return $pdf->dowload('test.pdf');
or you can save in specific directory of your project
return $pdf->save('path of your directory/filename.pdf');
This worked for me....
make the function call like this
return $pdf->download('invoice.pdf');

laravel Goutte filter some of <td> text is return right result while some is return nothing

Hi i am using laravel Goutte package to crawl some specific data for data analysis in my project while i am applying the filter some of td is return the right result while some is not return result anyone have the idea please help my controller code is
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Goutte;
use Goutte\Client;
use App\Http\Requests;
class MapController1 extends Controller
{
//
public function index()
{
$crawler = Goutte::request('GET', 'http://www.upsldc.org/real-time-data');
$crawler->filter('body')->each(function ($node) {
echo "<pre>";
//var_dump($node->text());
echo $node->filter('td')->eq(0)->text();
echo $node->filter('td.up_schedule')->text();
echo $node->filter('td')->eq(2)->text();
});
}
}
it is return Schedule (MW)Drawl (MW) but this echo $node->filter('td.up_schedule')->text(); row is return nothing. Thanks in advance

why method post not found in Illuminate\support\facade\input

I work with laravael 5.3.9 .
In my controller I use
Illuminate\Support\Facades\Input;
But when I try to get input from a user form using method post like that :
function add(){
$fullName = Input::post('fullName' , 'test');
I get this error .
the only method that Input class has is "get" .
I dont want that in my system I want to work with method post , delete , put ....
I guess, Input::post method is not used with L5.3. Use the Request facade OR $request to get your input variable.
Try this in your controller
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class area_owners extends Controller
{
function add(Request $request)
{
// I assume all these input variable have same name in you FORM.
$fullName = $request->input('fullName');
$smsCode = $request->input('smsCode');
$authorizationId = $request->input('authorizationId');
$areaNumber‌​ = $request->input('areaNumber‌​');
$neigh_project_Id = $request->input('neigh_project_Id');
$area_owners = DB::table('area_owners')
->insert(['fullName'=>$fullName,
'smsCode'=>$smsCode,
'authorizationId'=>$authorizationId,
'are‌​aNumer'=>$areaNumber‌​,
'neigh_project_Id'=‌​>$neigh_project_Id])‌​;
return view('area_owners_add', ['area_owners' => $area_owners]);
}
}
Let me know if it helps.

Resources