Undefined property: Illuminate\Database\Eloquent\Builder - eloquent

This strange thing is happening to me.I have the code below :
$state_image =States_Images::where('id_state', $id);
echo $delete_path=$state_image->name;
and the result is :
Undefined property: Illuminate\Database\Eloquent\Builder::$name
Someone help me pls :(

You need to finish the query with get() or first(). In your case probably:
States_Images::where('id_state', $id)->first();

Related

Fiddlers Jscript JSON.JsonDecode

This is what I have:
public static var users=Fiddler.WebFormats.JSON.JsonDecode('[{key:"20048039", value:"Some Name"}, {key:"204130"...);
This is what I want:
users.JSONObject[0].key or users.JSONObject[0].value
This what I use for investigation:
FiddlerApplication.Log.LogFormat('output: {0}', users.JSONObject[0]);
output: System.Collections.Hashtable
I know c#, but in FiddlerScript I need some help to read these values inside users.
What shall I do here ?
thanks.
ok, I found the solution by myself(ArrayList,Hashtable):
users.JSONObject[0]["key"])

undefine is not a function jquery auto complete

When trying to handle the data returned from autocomplete result set this always happens.
Any clue on this issue?
$("#search").autocomplete(suggest_url,{
max:100,
delay:10,
selectFirst: false
}).result(function(event, data, formatted)
{
do_search(true);
});
Thanks
Such error happens only if you are trying to call a function, but it is not a function.
x = 123;
x(); // produces «number is not a function
y = undefined;
y(); // produces exactly «TypeError: undefined is not a function»
«Uncaught type error» indicates that exception caused inside the lambla-style function. Thus, I hope, it is something wrong with do_searh identifier. Try to alert(do_searh) before calling it.
>>> UPDATE
This questions refers to another:
jQuery UI Autocomplete .result is not a function woes

use pdo connection inside php function

I have a database class for pdo access to my db.
Inside the class I have a function :
public function isSenderIdinDB($id)
I do in my script:
$conn=new Database($credentials);
$id=something;
echo $conn->isSenderIdinDB($id);
works fine.
Now I'd like to use a function in my script, like this:
echo fn_isSenderIdinDB($id);
with:
function fn_isSenderIdinDB($id) {
return $conn->isSenderIdinDB($id);
}
But it doesn't work. I tried with a:
global $conn;
inside the fn_isSenderIdinDB function, as suggested elsewhere on SO, without success.
Any help appreciated, thanks
Nicolas
This sounds like a variable scope issue, you could try passing $conn as a parameter to your function like this.
function fn_isSenderIdinDB(&$connObj, $id) {
return $connObj->isSenderIdinDB($id);
}
And then call your function like that :
echo fn_isSenderIdinDB($conn, $id);
Perhaps it would help if we could see the whole script or the errors your are getting.

Zend_Framework 1.12 SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax

Before anything I am aware of the multiple questions asked concerning this exception. I have looked through them but have not found an answer for my particular problem. Most of the questions use the Zend_Db_Table::getDefaultAdapter(); , and I am not using that. Instead I am using an Application_Model_DbTable_Name and am left wondering if it´s possible to do so.
Also, I do have access since that´s the first thing I checked when I saw the error. The database is local and I access it with the same user/password through MySqlWorkBench.
My goal is to delete a row when two columns meet the criteria set in the controller action, like so:
public function deleteAction(){
$request = $this->getRequest();
$this->_validateDigit($request->getParam('id'));
// _validateDigit(..) checks that the variable is numeric and if it´s not it redirects to
// an error page
$db = new Application_Model_DbTable_BecasPerfiles();
$select = $db->select();
$select->where('unidad=?', $this->_getUnit())
->where('id=?', (int) $request->getParam('id'));
$db->delete($select->getPart(Zend_Db_Select::WHERE));
$this->_redirect('/profile/view-profiles/unit/'.$this->_getUnit());
}
private function _getUnit()
{
return Zend_Registry::getInstance()['session']->unit;
//unit is nothing but a string
}
Here is my DbTable class (real simple):
class Application_Model_DbTable_BecasPerfiles extends Zend_Db_Table_Abstract
{
protected $_name = 'becas_perfiles';
}
Here is the error that spits out:
Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in
your SQL syntax; check the manual that corresponds to your MySQL server version for
the right syntax to use near 'AND (id=7))' at line 1
Here is what calls my attention AND (id=7)), see the extra parenthesis? where is that coming from?
Here is the result of var_dump($select->getPart(Zend_Db_Select::WHERE));
array(2) { [0]=> string(33) "(unidad='Galería de Arte ULPGC')" [1]=> string(10) "AND (id=7)" }
Just for the fun of it, I tried switching the order of the where clause:
$select->where('id=?', (int) $request->getParam('id'))
->where('unidad=?', $this->_getUnit());
Here is the output:
Message: SQLSTATE[42000]: ...
syntax to use near 'AND (unidad='Galería de Arte ULPGC'))' at line 1
There it is again, AND (unidad='Galería de Arte ULPGC')) that second parenthesis. I don´t really know if that´s the problem (but I figure it is because otherwise I don´t know what could posssibly be wrong).
I tried just using one where condition (like id), and it deleted just fine. I´d really appreciate your help, thank you!
The problem here is that there is a mismatch between what getPart() returns and what delete() expects.
As you already pointed out, var_dump($select->getPart(Zend_Db_Select::WHERE)); also returns the logical operators in the where statement, but the delete() operator either expects an array in the form "field => value" or a string containing the full where clause.
So the simplest (untested) approach to fix your problem would be to pass $db->delete(implode(' ', $select->getPart(Zend_Db_Select::WHERE))); so that delete() receives a fully qualified where clause as string instead of an array it cannot handle.

Function argument with jQuery selector

Folks, this works correctly for me to hide any element where the class name starts with "o"
function hider() {$("*[class^=o]").hide();}
Now I'd like to be able to pass that "o" string in as the function's argument, and I have trouble with the syntax. Any help is appreciated.
It seems that something like this will work:
function hider(startsWith) {
$("*[class^="+startsWith+"]").hide();
}
try it in this fiddle:
http://jsfiddle.net/JECUL/
function hider(className) {$("*[class^="+className+"]").hide();}
Call like so
hider("o");