Giter Site home page Giter Site logo

Comments (3)

ozdemirburak avatar ozdemirburak commented on July 22, 2024

Hi Rafael, that image field only holds the path, not a blob, so if you are planning to use Faker for that, you need to save that image then store the field in the database.

If you'd like to use that file template, then just create your form file like below.

@extends('layouts.admin')

@section('content')
    @include('partials.admin.form.init', ['action' => 'create'])
    @include('partials.admin.form.text', ['attribute' => 'title'])
    @include('partials.admin.form.file', ['attribute' => 'image'])
    @include('partials.admin.form.submit')
@endsection

And in your controller, pass the image field to store and update methods.

public function store(Request $request)
{
    return $this->createFlashRedirect(Article::class, $request, 'image');
}

from laravel-9-simple-cms.

rafamem avatar rafamem commented on July 22, 2024

Thanks man!

It didn't work, it saved me like this in the database: C:\Users[my_user]\AppData\Local\Temp\php1307.tmp

In ModelFactory.php I have this:

$factory->define(\App\Models\Article::class, function (Faker $faker) {
    $public_path = public_path('/img/blog/');
    return [
        'category_id' => $faker->numberBetween(1, 5),
        'content' => implode('<br/><br/>', $faker->paragraphs(8)),
        'description' => $faker->sentence(5),
        'published_at' => $faker->date($format = 'Y-m-d', $max = 'now'),
        'title' => Str::title($faker->words(4, true)),
        'image' => $faker->image($public_path,980,600, null, false),
    ];
});

And in ArticleController.php I have this:

/**
     * @param \Illuminate\Http\Request $request
     *
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
     * @throws \Exception
     */
    public function store(Request $request)
    {
        return $this->createFlashRedirect(Article::class, $request, 'image');
    }

from laravel-9-simple-cms.

safarovitch avatar safarovitch commented on July 22, 2024

@rafamem hi, I also run into this problem and for me it is simply windows directory separator problem.
File upload function in app/base/AdminController.php file on line 189 [$host, $uploadPath] = explode('/public/', $fullPath);
as you see explode function is looking for "/public/" with slashes which will cause problem on windows host. Just change slashes with backslashes like [$host, $uploadPath] = explode('\public\', $fullPath); or remove slashes and leave only 'public'. Hope this will be helpful

from laravel-9-simple-cms.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.