mardi 22 novembre 2016

Trying to get property of non-object laravel 5.1 on DB::first()

I'm using Laravel 5.1 on a project, and I'm getting "Trying to get property of non-object" error on this code:

$eval = DB::table('control_eval_risk_temp')
                        ->where('control_id','=',$control->id)
                        ->where('created_at','=',$max_date)
                        ->select('result')
                        ->first();
if ($eval->result  == 1)
{
     $cont += 1;
}

I have this error specifically on the "if sentence", but if I try this:

echo getType($eval);

That returns "object", and if I try:

echo $eval->result;

This returns 1 (so it have a value), and after return the message "Trying to get property of non-object", so I don't understand where is the mistake since the var $eval is an object and $eval->result have a value.

Thank's in advance!.



via Chebli Mohamed

Laravel - Using `SQL_CALC_FOUND_ROWS` with relationship

In my Laravel app I was doing an ordinary query on a model (ModelA) whilst making use of SQL_CALC_FOUND_ROWS and then performing SELECT FOUND_ROWS() afterwards to retrieve the count of all records since the first query used LIMIT and OFFSET.

This worked perfectly fine, but now that I've added a relationship to the model I was querying above, if I do the same query but using with->('modelB'), this query is performed after the initial query and before SELECT FOUND_ROWS() so I get the count of the ModelB results instead of ModelA as I was expecting.

Is there a way to make this work as desired where I get the count of the first query and not the relationship?

e.g. This works fine:

$query = ModelA::select([DB::raw("SQL_CALC_FOUND_ROWS *")])
    ->where('active', 1);

    // conditional ->where()'s

$query->skip(intval($skip))
    ->take(intval($take))
    ->orderBy($column, $dir);

$results = $query->get();

$total = DB::select(DB::raw("SELECT FOUND_ROWS() AS 'total';"))[0]->total;

but changing the first line to this doesn't:

$query = ModelA::with('modelB')
    ->select([DB::raw("SQL_CALC_FOUND_ROWS *")])
    ->where('active', 1);



via Chebli Mohamed

lundi 21 novembre 2016

How to pass PHP variable into Laravel DB::unprepared query

working with Laravel 5.1. I have this query below. It works fine in phpMyAdmin. It will also work if I hard code the $category and the $value. But no number of concatenations and / or escaping of the variables gets the query to run in my controller. I am using use Illuminate\Support\Facades\DB; I have tried encapsulating the query with single quotes and double quotes, to no effect. I am using PHPStorm and it even says the query is correct, but it is not. What am I doing wrong ??

public function addNode(Request $request)
{

$category = $request->input('parent_category');
$value = $request->input('new_category');


$result = DB::unprepared("
LOCK TABLE nested_categories WRITE;
SELECT @myLeft := lft FROM nested_categories
WHERE name =  '.\'$category\'.';
UPDATE nested_categories SET rgt = rgt + 2 WHERE rgt > @myLeft;
UPDATE nested_categories SET lft = lft + 2 WHERE lft > @myLeft;
INSERT INTO nested_categories(name, lft, rgt) VALUES( '.\'$value\'.', @myLeft + 1, @myLeft + 2);
UNLOCK TABLES;");

return redirect('nested_categories');
}

TKS !!



via Chebli Mohamed

missing images and home page when moving laravel 5.2 project to live server

images works fine in localhost as src="/lr/public/bootstrap/images/photo.jpg" but don't work on live server

error messages on live server is failed 404 not found http://ift.tt/2ffkQXK

note : when i remove /lr/public images works on live server

my cpanel root directory is /home/ad

in /home/ad >> i have folder'lr' that containe my project and i deleted folder public in it

in public_html >> i have contents of folder public >> bootstrap - uploads - index.php ..... etc

second prob

when i try access www.mysite.com it show my 404 page

but when i try access www.mysite.com/home it works fine and show my home page

i want when access www.mysite.com show home page directly

my public_html/index.php

require __DIR__.'/../lr/bootstrap/autoload.php';
$app = require_once __DIR__.'/../lr/bootstrap/app.php';



via Chebli Mohamed

dimanche 20 novembre 2016

App Domain when using localhost for facebook authentication laravel 5.1

hello so im using socialite in laravel 5.1 and using it in localhost still and in also using xampp. When i click the login button i created it has an error just like this enter image description here

do i have to change the settings in my facebook dev settings? right now it looks like this enter image description here

do i need to have changes on this? on my .env file

FACEBOOK_CLIENT_ID=xxxxx
FACEBOOK_CLIENT_SECRET=xxxxxxx
CALLBACK_URL=http://localhost/<my projectname>/public/auth/facebook/callback

any ideas what im doing wrong? thanks in advance



via Chebli Mohamed

Trying to render Anchor using Blade and Angular Js

I am using Angular Js with Blade and Laravel 5.3.15

Code in Blade.



Code in Route.

Route::get('/', function() {                    
    return view('Account.Login');
});

When i check the output in web page, it displays the code which I wrote in Blade. i.e

I am trying to render Anchor tag, Am I missing something?



via Chebli Mohamed

facebook authentication using laravel 5.1 socialize

hello im using localhost so i have recently switched to laravel 5.1 and im trying to use 'socialite' it provides so i have updated my config , services and the .env files so in my routes i also added these codes

Route::get('/', function () {
return view('welcome');
 });
 Route::get('auth/facebook', 'Auth\AuthController@redirectToProvider');
 Route::get('auth/facebook/callback','Auth\AuthController@handleProviderCallback');
Route::get('home', array('as' => 'home', 'uses' => function(){
return view('home');
}));

then in my AuthController i have these codes enter image description here

in my view the button 'login with facebook' has the href of auth/facebook but what happens is facebook is giving me an error saying enter image description here

im still confused on where my error is. any idea what im doing wrong? thanks for advices.



via Chebli Mohamed