This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------ | |
MANY-TO-MANY RELATIONSHIP ( PIVOT TABLE ) | |
------------------------------------------------------------ | |
1) Shop.php | |
2) Product.php | |
class Shop extends Model | |
{ | |
/** | |
* The products that belong to the shop. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Should we add orderBy in every query? No, we can define that in relationship itself. | |
Our usual Eloquent relationship looks something like this: | |
class Category extends Model | |
{ | |
public function products() | |
{ | |
return $this->hasMany('App\Product'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I find more and more Eloquent functions that are rarely used, so continue posting these short tips on the blog. Here’s the next one. | |
Simple Eloquent relationship goes like this. | |
class Author extends Model | |
{ | |
public function books() | |
{ | |
return $this->hasMany(Book::class); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How can i get data into this format: | |
[ | |
[ | |
1499779800000, | |
145.53 | |
], | |
[ | |
1499866200000, | |
145.74 | |
], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm in a bit of a situation with whereHas, the problem is I got a array with keys, I need to use those selected key to find results that contains all (ids that is contained within the array). The problem is it works with one, but when having more than one it does not work. | |
Solution: | |
Way-1 | |
$keys = array_keys($request->genres); | |
$list = Movie::with('genres'); | |
foreach($keys as $k => $v) { | |
$list->whereHas('genres', function ($query) use($v) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="text" name="sdms[]"> | |
<script> | |
$(document).on("keyup", ".sdms", function() { | |
var sum = 0; | |
$(".sdms").each(function(){ | |
sum += +$(this).val(); | |
}); | |
document.getElementById("corporate").innerHTML = sum; | |
}); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$i = 1; | |
global $wpdb; | |
$getdonar = $wpdb->get_results("SELECT * FROM wp_donors"); | |
foreach ($getdonar as $row){ ?> | |
<tr> | |
<td><?php echo $i; ?></td> | |
<td><?php echo ucfirst($row->donor_name); ?></td> | |
</tr> | |
<?php $i++; } ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
in the create() method in the LoginController you must return the $user that worked for me | |
protected function create(array $data) | |
{ | |
$user = User::create([ | |
'username' => $data['username'], | |
'email' => $data['email'], | |
'password' => bcrypt($data['password']), | |
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Two Level | |
@foreach($categories as $category) | |
<option value="{{$category->id}}">{{$category->name}}</option> | |
@foreach($category->subcategory as $sub) | |
<option value="{{$sub->id}}">-{{$sub->name}}</option> | |
@endforeach | |
@endforeach | |
// Three Level |
OlderNewer