Comments (6)
What Laravel version?
from tags.
Can't reproduce on Laravel v5.1.21.
from tags.
Laravel 5.1.21
tags: 2.0.2
from tags.
@rutger1413 I can't really reproduce any issue so i assume you're doing some wrong on your end, as you can see below, both snippets returns the expected response, considering i only have one product on the database.
Either you changed your models namespaces or you have something else going on your end that you'll need to debug.
Using allTags method
var_dump(App\Product::allTags()->lists('name'));
Response
object(Illuminate\Database\Eloquent\Collection)[140]
protected 'items' =>
array (size=3)
0 => string 'foo' (length=3)
1 => string 'bar' (length=3)
2 => string 'baz' (length=3)
Using a model entity
var_dump(App\Product::find(1)->tags->lists('name'));
Response
object(Illuminate\Database\Eloquent\Collection)[139]
protected 'items' =>
array (size=3)
0 => string 'foo' (length=3)
1 => string 'bar' (length=3)
2 => string 'baz' (length=3)
from tags.
Ok I see what the issue is.
Model::allTags()
returns a QueryBuilder object.
Model::allTags()->get()
Returns the collection which is what I would have expected. The documentation isn't clear about this. I didn't var dump the result which is something I should have done.
By doing ->lists('name')
the QueryBuilder object is now a collection. It would be good to point this out or to change allTags() to include the ->get()
like so:
/**
* {@inheritDoc}
*/
public static function allTags()
{
$instance = new static;
//return DB::table('tags')->where('namespace', $instance->getEntityClassName())->where('count','>','0')->get();
return $instance->createTagsModel()->whereNamespace(
$instance->getEntityClassName()
)->get();
}
from tags.
You can submit a PR to the documentation if you want.
from tags.
Related Issues (20)
- tag duplicates on Model HOT 1
- Append tags attribute to model HOT 1
- Laravel 5.4 HOT 2
- namespace is necessary? HOT 1
- Cannot remove tagged tag which has name similar to SQL commands HOT 3
- FatalThrowableError: Call to a member function pluck() on string HOT 3
- What would be the best approach to heirarchical tagging HOT 3
- Method lists does not exist. HOT 3
- How to get the Tag and Tagged models to use timestamps HOT 2
- php 7.1 problem HOT 3
- Get all tags sorted by counter HOT 2
- untag() didsnt work HOT 1
- still untag() didsnt work HOT 1
- Laravel 5.7 support HOT 2
- Undefined constant 'Cartalyst\Tags\TagsServiceProvider HOT 1
- Please improve documentation about matching tag based on slug when calling WithTag() HOT 1
- The typing added to setSlugGenerator now prevents it from accepting a closure. HOT 2
- Support Laravel 8 HOT 2
- index/relation on tagged.tag_id
- Support Laravel 9 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tags.