Jump to content

Laravel Tips


Askancy

Recommended Posts

  • Admin

Laravel Tips

 

Se la tabella del DB non contiene i campi timestamp created_at e updated_at, si può specificare che il modello Eloquent non li userà, con la proprietà $timestamps = false.
 

class Article extends Model
{
    public $timestamps = false;
}

 

Se si vuole incrementare una colonna del DB in una tabella, basta usare la funzione increment(). Inoltre, è possibile incrementare non solo di 1, ma anche di un certo numero, ad esempio 50.

Article::find($article_id)->increment('view_count');
User::find($user_id)->increment('points', 50);

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. to insert a cookie message.