aondoe

Experience

550

0 Best Reply Awards

  • Member Since 5 Months Ago
  • 2 Lessons Completed
  • 1 Favorite

26th September, 2018

aondoe left a reply on Files Don't Upload To The • 2 weeks ago

Thanks for your tips. I forgot to remove one of the validation rules. I will read the link you posted thanks.

aondoe started a new conversation Files Don't Upload To The • 2 weeks ago

Hello. I'm trying to upload files into the public folder. I've already created a link to the storage folder using artisan. But for some reason, the file title uploads to the MySQL field. Has anyone else experienced this?

The main code is in the if-statement near the bottom of the code.

Here is my Controller

    public function store(Request $request){
                request()->validate([
                    'title' => 'required|min:2',
                    'subject' => 'required|min:4',
                    'content' => 'required|min:50',
                    'featured_img' => 'sometimes|image'
                ]);

                $this->validate($request, [
                    'title'=>'required|min:3',
                    'content'=>'required|min:10',
                    'featured_image' => 'sometimes|image'
                ]);
                
                PostIt::create(['title'=>$request->title,
                                'content'=>$request->content,
                                'featured_img' => $request->featured_img
                ]);

                if ($request->hasFile('featured_img')){
                    

                    $path = $request->file('featured_img');
                    // $fileName=$featured_img->getClientOriginalExtension();
                    $image->move(base_path('/images'), $fileName);
                    $post->update(array_merge($request->all(), ['featured_img' => $path]));
                    
                    return "Here is the path: ".$path;
                }
                return redirect()->route('posts.index');
}

Here is my form which contains the upload field

<form onsubmit="return confirm('Are you sure you want to edit the post {{$post->title}}?')" action="{{route('posts.update', $post->id)}}" method="POST" type="multipart/form-data">
                    @method('put')
                    @csrf
            <div class="form-group">
                        <label for="title" >Title</label>
                        <input type="text" name="title" id="title" class="form-control" value="{{$post->title}}">
            </div>
        <div class="form-group">
                    <h2>Your current subject is {{$post->subject}}</h2>
            </div>
            
        <div class="form-group">
                <input type="file" name="featured_img">{{$post->featured_img}}
        </div>

Any help would be great. Thanks

16th September, 2018

aondoe left a reply on File Upload Not Working • 4 weeks ago

Hey you guys are awesome. This framework is awesome, and I'm working constantly to get better. I finally got it to work. My $fillable in my model didn't match the column I was trying to upload to. So now I'm able to upload finally! Thank you all.

aondoe left a reply on File Upload Not Working • 4 weeks ago

Hey tykus thanks for your prompt response and assist, but I'm getting a

"Call to a member function store() on null" error, on this line:

 $path = $request->file('featured_img')->store(public_path());
       

I suspect the request isn't to the proper file. I'm not sure actually. But I thank you for your help. I will keep working at it.

aondoe left a reply on File Upload Not Working • 4 weeks ago

Hey tykus. No I was following online examples, and I just wanted it to be stored inside the storage/app/public/ directory

aondoe left a reply on File Upload Not Working • 4 weeks ago

Hey guys thanks for your responses. I omitted the @csrf token from my form above. I actually include that right below the tag.

    public function update(Request $request, PostIt $post)
    {
        //The code below will update the post/record in the database.
        request()->validate([
                    'title' => 'required|min:2',
                      'content' => 'required|min:50',

                  ]);
                  
        $post->update($request->all());

        session()->flash('message', 'Your post has been created successfully');
        return redirect()->back();
    }

Here's the code from the controller:

namespace App;

use Illuminate\Database\Eloquent\Model;

class PostIt extends Model
{

    protected $fillable=['title','content', 'subject','featured_image'];

    protected $guarded=[];//For guarded data if needed


    //
}

aondoe started a new conversation File Upload Not Working • 4 weeks ago

Hello everyone.

I'm having trouble with file upload in laravel 5.6 I'm trying to upload images to my CMS I've created with Laravel.

I have a table called "post_its" below:

    public function up()
    {
        Schema::create('post_its', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('content');
            $table->text('subject');
            $table->text('featured_img');
            $table->timestamps();
        });
    }

I had to add a column in the table to upload images so I did so like below:

    public function up()
    {
        Schema::table('post_its', function(Blueprint $table)
        {   
            //add a column to the post_its table and give it 100 characters. Also specify 100 characters
            $table->string('featured_img', 100)->nullable();
        });
    }

Here's my form data I'm trying to fix, as you can see below:

<form action="{{route('posts.update', $post->id)}}" method="POST" type="multipart/form-data">
<!--other form fields are here as well, but omitted for brevity-->
        <div class="form-group">
                <input type="file" name="featured_img" title="Featured image">
                
        </div>
</form>

Every other field works and updates the database table, but not this upload field. All the fields under the featured_img column says null. I was hoping after I added this column I could edit this column. Any suggestions?

aondoe left a reply on File Upload Not Working And How To Move Upload Folder • 4 weeks ago

Did this work for you?

12th July, 2018

aondoe left a reply on I'm Trying To Modify My AuthServiceProvider.php File, I Get An Error "Call To Undefined Method Illuminate\Support\Facades\Gate::define()". Anyone Else Having This Trouble? • 3 months ago

Please dis regard this question. I didn't use the correct path. Instead of the path listed in my code above I should've typed:

use Illuminate\Contracts\Auth\Access\Gate as GateContract;

instead of: Illuminate\Support\Facades\Gate

27th May, 2018

aondoe left a reply on Laravel 5.6.9 : Php Artisan Migrate - Problem • 4 months ago

Thank you takdw your solution worked for me.

15th May, 2018

aondoe left a reply on File Assets/css/laravel.css Not Defined In Asset Manifest • 5 months ago

Hey bobbybouwmann. Thank for your help. I tried to run the commands but they didn't work at first. I got this weird node error.

So I uninstalled nodejs and npm.

After that, I recreated the project and tried your commands and everything worked fine. Thanks a lot.

aondoe left a reply on Where Are You All From? • 5 months ago

In Atlanta, GA by way of West Africa

aondoe started a new conversation File Assets/css/laravel.css Not Defined In Asset Manifest • 5 months ago

When I try to click on 'register'(register.blade.php) I get this error message:

'File assets/css/laravel.css not defined in asset manifest'

When I click the login page on public/index.php I get this message: 'View [layouts.app] not found'

When I followed the path: assets/css/laravel.css

I realize I'm missing the CSS directory in my assets folder.

Has anyone else had these issues?

Thank you for your help in advance.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.