Laravel Eloquent query similar to findorfail - select

I would like to look up and return an object referenced by a different column to that of id.
As far as I know there isn't another method similar to Task::findOrFail($id) but that can reference another field. For example:
Task::findOrFail('column_name' = 'column_data');
I'm currently using
Task::where('tid' , '=', $tid)->first();
Is this possible?

Maybe you can use the firstOrFail() function of Laravel.
Task::where('column_name', '=' ,'column_data')->firstOrFail();

Related

getting the relation data from where clause in view

I have the following query
$partner = DeliveryPartner::with(['deliveryPartnerImage' => function($q) {
$q->where('image_type', '=', 'logo');
}])
->find($id);
this works. for a partner with a logo it shows a relation with 1 item like so
and when i change the where clause to something non existent for example $q->where('image_type', '=', 'testtesttest');
it shows a empty array like this
so i know my query works but how to get this data in the view?
i did $partner->deliveryPartnerImage()->first() But for some reason this always shows data? also when i change the query... so im guessing im doing this wrong but i can not find another way to do this?
Use this:
$partner->deliveryPartnerImage
$partner->deliveryPartnerImage()->first() executes a new query without the where() constraint.

SAPUI5 TableSelectDialog Search Value

I'm using TableSelectDialog control where I'm also performing some search. In order to get the search value on livesearch, i'm using oControlEvent.getParameters.value but it returns me undefined as I see it in an alert box.
Any idea why it is giving me undefined or any other way I can get the value I typed in search field.
This works with oEvent.getParameters().value.
Another idea, as most used way to find the query value is for a SeachField, we use
oEvent.getSource().getValue
Here, you can also find the query string similarly:
oEvent.getSource()._oSearchField.getValue()
Adding to the other answers here you can also do:
onSearch: function(oControlEvent) {
oControlEvent.getParameters("value");
}
https://sapui5.hana.ondemand.com/#/api/sap.m.TableSelectDialog/events/search

FindBy property in TYPO3 Extbase MVC is not working

I'm unable to run the FindBy magic function property in Extbase MVC
$title=array(0 =>'Books Day');
$each_event=$this->eventRepository->findByTitle($title);
$each_event is returning an object of type TYPO3\CMS\Extbase\Persistence\Generic\QueryResult .
How do I make this work?
I also tried passing in a string to findByTitle and findByOne. Both don;t work! :(
I'm using TYPO3 6.1 and extension builder.
The last part of those magic functions always needs to be a field in the database. So "title" must be in your model. You might have a field "one" for your object, but I guess you meant findOneByTitle?
The object type QueryResult is correct. You can turn it into an array for debugging purpose for example:
$foo = $query->execute()->toArray();
By the way: check wether your eventRepository is null or not and you could try this to see if it works at all:
$result = $this->myRepository->findAll();
Try
$each_event=$this->eventRepository->findByTitle($title)->toArray();
Reference to the QueryResult.
As said in the documentation, it returns a QueryResultInterface|array.
As a consequence you have to loop over the result like this:
foreach($each_event as $single_event) {
$single_event->getProperty();
}
If you are sure that it returns only one single value you could also access it by the index 0:
$each_event[0]->getProperty();

wordpress 3.2.1 database query

i am trying to make a simple selection in a wordpress table (created by a plugin). the table is named reduceri , and has the following columns: id, post, category.
so, i am trying to take all the category values, when the post is equal to the current post id.
the way i am doing the query is:
$the_query = "
SELECT $wpdb->reduceri.category
FROM $wpdb->reduceri
WHERE $wpdb->reduceri.post = ".$post_id."
";
$my_reduceri = $wpdb->get_results($the_query);
but when i var_dump the $my_reduceri all i get is an empty array: array(0) { } even though there should actually be some results... any idea where i am wrong (in the query)?
thank you
Did you declared global $wpdb; before using this query?

Zend db table find just like fetchRow

I´m using find() to retrieve a value from the database, but It returns an array with the objects, I would like that it return to me just the object like fetchRow returns, is there any change or similar thing to do?
Thanks, and best regard´s.
Well, It was so simple, for those that are in doubt, the solution is:
Zend_Loader::loadClass('News');
$db = new News();
$row = $db->find($id)->current();
That´s it, thanks.