I'm noob in Laravel, I have written a policy and I have used it in blade template, and I don't understand how work the parameter match.
Shnippets from my code:
UserPolicy.php
public function hasModifyUserStatus(User $currentUser, $editableUser) {
echo $currentUser->id.' | '.$editableUser->id;
...
userform.blade
#can('hasModifyUserStatus', $editableUser, $editableUser->id)
the results: 1 | 3 where 1 is my current user 3 is the editable user id.
so, in the $currentuser is the Auth::user() and in the editableUser is the really editableuser, but in #can I put the $editableUser and the $editableUser->id :)
So I don't understand how it is working.
Could somebody help me?
(I have read the documentations, but I haven't found and I'm looking it more than 2 hours :-) )
My Laravel version is 5.2 with PHP 7.
Related
I was using this function in 5.3 and now when I try to use it in 5.4 like this:
$post->tags()->getRelatedIds();
I am getting errors that function does not exist, I checked the documentation for 5.4 and it's not there anymore.
Anyone knows why this usefull function was removed and what I can do to get all ids from related model?
In Laravel 5.4 and 5.5 the getRelatedIds is replaced by allRelatedIds.
$post->tags()->allRelatedIds();
I can't speak for reasons why it has been removed but if you know the primary key name ahead of time (i.e. all your tables have an id column) you can simply do
$post->tags()->select('id')->pluck('id');
if you want a more generic way you'd need to jump through some hoops
$related = $post->tags();
$post->tags()
->select($related->getQualifiedKeyName())
->pluck($related->getKeyName());
I'm upgrading from Laravel 4.2 to Laravel 5.1. I have a Stripe account that works with Cashier in my Laravel 4.2 version that I built watching a Laracast on Stripe and Cashier. However, in Laravel 5.1 a new table column is required called "stripe_subscription." I tried researching the Stripe documentation, the Cashier documentation and the Laravel documentation, but couldn't find anything about what this variable is or does.
After simply adding it to my database with a new migration, it looks like Stripe is up and running again with Cashier in my Laravel 5.1 version. However, I was wondering if anyone knows what this variable does or where I can learn more about it. I just guessed that it should be a string, which I was really unhappy about having to guess, but it seemed to work.
Here is some code relevant to this variable from my project:
From my migration:
$table->string('stripe_subscription')->nullable();
From the Cashier file Billable.php:
public function setStripeSubscription($subscription_id)
{
$this->stripe_subscription = $subscription_id;
return $this;
}
public function getStripeSubscription()
{
return $this->stripe_subscription;
}
public function deactivateStripe()
{
$this->setStripeIsActive(false);
$this->stripe_subscription = null;
return $this;
}
I'm just noticing it does actually say that stripe_subscription is a string in the php file, but I'd rather see something in formal documentation about it. Further, as far as I can tell, this variable is unnecessary because there is also a "stripe_plan" variable. The "stripe_subscription" variable contains a random string, while the "stripe_plan" variable is the name of the plan, like "monthly" or "yearly."
If anyone can give me some guidance on where I can learn more about this variable and how to work with it, I'd appreciate it.
I am learning about Laravel 4 and I'm trying its pagination. I created a simple query to test the pagination, yet it always end up hanging. If I use get(), it works fine, but when I replace get() with paginate(), it hangs. Here is my code:
DB::table("samp_tbl")
->select("id","activity")
->whereNull("deleted_at")
->orderBy("id","desc")
->paginate(5);
Could someone tell me what's wrong with my code?
In case anyone else comes across this issue it's because you are using orderBy. In the Note: area on this page http://laravel.com/docs/4.2/pagination#usage it explains that laravel has issues with groupBy. However I also would assume this would go for orderBy as well. Writing a custom query would be recommended in your case.
create a model for your database and it will work fine
I read that Laravel 4 is not going to change much on the surface, saying that much of the old code would be compatible.
I try to use Fluent's insert_get_id like it says in the docs, but the function doesn't exist.
Am I doing it wrong? If not, are there more changes in Fluent and / or Eloquent?
Laravel 4 has been changed to become PSR-1 complaint and as such is now camelCased instead of snake_cased. Try changing to insertGetId().
I believe functions went from underscores to camelCase... try insertGetId
im totally new to rails. here my question:
i made an app with articles and comments and use devise for authentication
sadly im only able to post 1 hyperlink so this is the middle part of my post with the files at gist: https://gist.github.com/771366
the article_id is pre selected in the comments/_form - but the user_id isnt. i googled a lot, tried value => session[:user_id] and others, but nothing worked
would be great if someone could tell me how it works ^^
thx
If you are trying to get the current user's ID you can do
current_user.id
in your view or in your controller