vipin93's avatar

How to show few content about image

Hey I try to make where user can upload images and I want show that images in pagination and every image have content(may be long) but I want show some content and link it to a page only about this image where it have comment long content and many more like in laracasts website ?

thanks

0 likes
8 replies
davorminchorov's avatar
Level 53

use the helper function str_limit($value, $limit = 100, $end = '...')

Example:

$posts = Post::all();
$excerpt = str_limit($posts->body,  100, '...');

// in your view where you show all of the posts instead of listing the body, list the $excerpt
$posts->excerpt //instead of $posts->body

Laravel 5 Helpers

vipin93's avatar

@Ruffles I 'm getting error Undefined property: Illuminate\Database\Eloquent\Relations\HasMany::$description

vipin93's avatar

@Ruffles I changed and when I try different way I got this error

ErrorException (E_UNKNOWN) Undefined property: Illuminate\Pagination\Paginator::$description Open: C:\lamp\www\demo\app\controllers\ImageController.php return View::make('images.show' )->with('title', 'image'); }

public function create()
{   
    $images = $this->imageRepository->getAllUser(Auth::user());

    $excerpt = str_limit($images->description, 50 , '....');

    return View::make('images.create',compact('images'))->with('title', 'Upload images');
davorminchorov's avatar

replace 'title' and 'Upload images' with 'images' and 'excerpt' in the return statement. It looks like you don't have a description field in the table. Check the field name.

Please or to participate in this conversation.