I'm trying to get all posts from database and show the in a view. The posts that I want are stored in database with post_type = product.
I got this error:
Allowed memory size of 134217728 bytes exhausted (tried to allocate 62918656 bytes)
this is my Model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class GetPostModel extends Model
{
/**
* @param $filed
* @param $value
* @return mixed
*/
static function get_posts_by_filed($filed, $value)
{
$result = DB::table('posts')->where($filed, $value);
return $result;
}
}
this is what I do in Controller:
public function all_products_page(Request $request)
{
//getting the products
$all_products = GetPostModel::get_posts_by_filed('post_type', 'product');
echo '<pre>';
print_r($all_products);
echo '</pre>';
}
->get()after your where, or else you're just returning the QueryBuilder object instead of the actual results.