mardi 27 décembre 2016

How to pass GET Parameters in encrypt format in URL using Laravel form with GET Method?

I want to encrypt parameters when form submit. I am using laravel 5.2 version and when form submit that time I am using get method for submit the form. But when submit the form that time show all parameters in URL. So all this parameters I have to encrypt. For example

http://localhost:8000/get/experiences?category_id=18

to

http://localhost:8000/get/experiences/AQBBShSqt4zxsClTymwBhjIUP1kG7HEoqhoKMfAAlsMk2ZUOxStqGLAFFg0mM1nRKMEVVbB97xCvfRJTP0ZH3k1Am

How can I do this?



via Chebli Mohamed

Gulp js file not working

[This is my terminal ][1] Here is my script

So please help I am new in gulp.



via Chebli Mohamed

Laravel tags CRUD

I have read or watched many laravel tutorials on the web,most of the tutorials' tagging system have a feature:

The tag CRUD has their own router,first,add new tags and select tags when create new post.But if I want to dynamically add tags or update tags when create post like wordpress, How can I do ?



via Chebli Mohamed

Parent model still returns soft deleted child instance

I have a parent model Library which has many Books. Eloquent makes it so easy to define the relationships. I have enabled softdeleting on the book mode using the SoftDeletes trait.

Problem:

When I delete a book instance, the deleted_at attribute on the book instance is set to the current timestamp (as expected).

But when I query all the books that belong to the Library, the result contains all the books, including the ones that were deleted.

I only want to get the books that have not been deleted.

class Library extends Model {
   public function books() {
      return $this->hasMany(Book::class);
   }
}

class Book extends Model {
   use SoftDeletes;
   public function library() {
      return $this->belongsTo(Library::class, 'library_id');
   }
}

$softDeleteBook = Book::find(1);
$softDeleteBook->delete();
$books = Library::find(1)->books;
// $books contains even $softDeleteBook
// I do not want to get $softDeleteBook



via Chebli Mohamed

Many to many relationships store and update in laravel

I create three tables:

Post Table

id--title--body

Tags Table

id--name

post_tag

post_id--tag_id

Post Model

public function tags()
{
    return $this->belongsToMany('App\Tag');
}

Tag Model

public function posts()
{
    return $this->belongsToMany('App\Post');
}

This is a many to many relation

I want to store tags when add new post and update tags when update post, and I use bootstrap-tagsinput plugin, for add post,I use this method to store the new tags:

public function storeTags($post, $tags)
{
    $tagInputArr = explode(',', $tags);
    $tagArr = [];
    foreach ($tagInputArr as $tag) {
        $tagArr[] = new Tag(['name' => $tag]);
    }
    $post->tags()->saveMany($tagArr);
}

$post is the new post object, $tags is the tag string from $request.

For update post,I have a problem,when I view the edit post page,the default tags is selected from database,If I want to add new tags the storeTags method is not work.



via Chebli Mohamed

How to have multiple layers of hasMany() relation for Laravel 5?

Let say I have tables like the following:

order
 order_id | customer_name | delivery_address        
 1        | David         | ABC Road, DEF district 
...........Some other record ..............

order_dish
order_id | dish_id | dish_name
1        | 1       | chicken wing
1        | 2       | meat pie
1        | 3       | onion ring
...........Some other record ..............

dish_ingredient
dish_id | ingredient
1       | chicken wing
1       | salt
1       | oil
2       | pork meat
2       | flour
3       | onion
...........Some other record ..............

In Laravel 5, if I want to get all dishes of an order, I can do:

$order = Order::hasMany('App\OrderDish', 'order_id')->get();

Is there a way I can get all ingredients needed for an order in one line?



via Chebli Mohamed

How do I query by geolocation in Laravel 5?

I am looking to add a geolocation attribute to my "Candidate" Eloquent model. I want to find Candidates based on their location. For instance, find all Candidates within 20 miles of San Francisco. What should my Eloquent model look like to store a location in the database?

How do I query for candidates based on their location? I am using Laravel 5.3.



via Chebli Mohamed