mada72
279
9
Laravel

seed photo

Posted 1 month ago by mada72

Hello,

I made: php artisan db:seed- but I can't see my photos

Photo factory

use App\Photo;
use Faker\Generator as Faker;

$factory->define(Photo::class, function (Faker $faker) {
    return [
        'file'=>$faker->imageUrl($width = 400, $height = 400) ,
    ];
});

ProductContrller

public function store(Request $request)
    {
        //dd($request->all());
        $input = $request->all();//alle velden uit het formulier in $input
        if($file = $request->file('photo_id')){
            $name = time().$file->getClientOriginalName();//samenstelling bestandsnaam
            $file->move('images', $name);//het kopieren naar de map images
            $photo = Photo::create(['file'=>$name]);//in de tabel photo id en naam aanmaken
            $input['photo_id'] = $photo->id; //
        }

        $product = new Product();

product index blade

extends('layouts.admin')
@section('content')
    <h1>All Products</h1>
    <table class="table table-striped">
        <thead>
        <tr>
            <th scope="col">Photo</th>
            <th scope="col">Name</th>
            <th scope="col">Category</th>
            <th scope="col">Title</th>
            <th scope="col">Description</th>
            <th scope="col">Price</th>
            <th scope="col">Quantity</th>
            <th scope="col">Created</th>
            <th scope="col">Updated</th>
        </tr>
        </thead>
        <tbody>
        @if ($products)
            @foreach($products  as $product)
                <tr>

                    <td>
                        <img height="50" src="{{$product->photo ? asset($product->photo->file) : '' . ' https://via.placeholder.com/100x100'}}" alt="">
                    </td>

inspect element for photo

<img height="50" src="http://localhost/larabijoux/public/images/https://lorempixel.com/640/480/?46563" alt="">

that is not correct....but I don't know how is correct

Thx!

Please sign in or create an account to participate in this conversation.