forteirp

forteirp

Member Since 4 Months Ago

Experience Points
450
Total
Experience

4,550 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
450 XP
Aug
07
2 months ago
Aug
04
2 months ago
Activity icon

Replied to When Logged In As A User The Buefy Stop Working In Laravel Using Vue

Here's package.json

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {
        "axios": "^0.18",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^4.0.7",
        "lodash": "^4.17.5",
        "popper.js": "^1.12",
        "resolve-url-loader": "^2.3.1",
        "sass": "^1.15.2",
        "sass-loader": "^7.1.0",
        "vue": "^2.5.17",
        "vue-template-compiler": "^2.6.10"
    },
    "dependencies": {
        "buefy": "^0.7.10",
        "bulma": "^0.7.5",
        "font-awesome": "^4.7.0"
    }
}

and here's my webpack.mix.js

    const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css');

and to your second question, no there is nothing being added...

Activity icon

Started a new Conversation When Logged In As A User The Buefy Stop Working In Laravel Using Vue

i recently learning about Laravel using vue...

I'm using Laravel 5.8, Bulma 0.7.5, Buefy 0.8.1, and Vue

My issue is that when I'm logged-out the Buefy CSS works fines but ones I log-in, it stops working...

Here's are a few screenshots so you can see what I'm talking about...

Here's what it looks like when I'm logged-out https://imgur.com/inOTzgv

and here's what it looks like when I'm log-in https://imgur.com/Qgq52d4

Here's my app.js

require('./bootstrap');

window.Vue = require('vue');
import Buefy from 'buefy';
Vue.use(Buefy);


var app = new Vue({
            el: '#app',
             data() {
                return {
                    auto_password:      true,
                    password_options: 'keep'
                }
            }
            });
        

and here's My cpanel.blade.php

    <html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'EthicallySpeaking') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts 
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">-->

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
    @yield('styles')
</head>
<body>

    <div id="app">
          @include('inc.navbar')
          @include('inc.messages')
          @include('inc.side_navbar_cpanel')
        <div id="app" class="cpanel-dashboard-area flex-container">       
              @yield('content')
        </div>
    </div>
        @yield('scripts')
            
</body>
</html>

and here's the edit.php form that I'm having the issue with...

@extends('layouts.cpanel')

@section('content')
<section class="section">
        <div class="container">
    
            <div class="columns m-l-10">
                <div class="column is-10">
                    <h1 class="title">Edit User Profile</h1>
                </div><!-- end column is-10 -->
            </div><!-- end columns -->
   <hr/>
        <div class="columns">
                <div class="column">
            <form action="{{route('users.update', $user->id)}}" method="POST">
            {{method_field ('PUT')}}
            {{csrf_field()}}
                <div class="field">
                    <label for="name" class="label">Name</label>
                    <p class="control">
                        <input type="text" class="input" name="name" id="name" value="{{$user->name}}">
                    </p>
                </div>
                
                <div class="field">
                    <label for="email" class="label">Email</label>
                    <p class="control">
                        <input type="text" class="input" name="email" id="email" value="{{$user->email}}">
                    </p>
                </div>
                
                <div class="field">
                    <label for="password" class="label">Password</label>
                        <div class="field">
                            <b-radio v-model="password_options" native-value="keep" name="permission_type">Do Not Change Password</b-radio>
                        </div>
                        
                        <div class="field">
                            <b-radio v-model="password_options" native-value="auto" name="permission_type">Auto-Generate New Password</b-radio>
                         </div>  
                         
                         <div class="field"> 
                            <b-radio v-model="password_options" native-value="manual" name="permission_type">Manually Set New Password</b-radio>
                                <p class="control">
                                    <input type="text" class="input" name="password" id="password" v-if="password_options == 'manual'" placeholder="Manually give a password to this user"> 
                                </p>
                        </div>
                </div>
                
                <button class="button is-success m-t-20">Edit User</button>
                
            </form>
            </div><!-- end column is-10 -->
            </div><!-- end columns -->
            
            
       </div><!-- end container -->

</section>
@endsection

I wanted to know if anyone know why this is happing?

Jun
20
4 months ago
Activity icon

Replied to Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

Has my show() method...

https://i.stack.imgur.com/uo1zh.jpg

this worked better for me...

{!! html_entity_decode($post->body_html) !!}

but my raw phpMyAdmin still has the tags in it...

If anyone can show how to fix my raw data I would really appreciate it but for now, this works.

Thx for all the help @deansatch...

Activity icon

Replied to Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

@deansatch Good eye sir... that work for my show view...

but what about the phpMyAdmin? The tags are still there?

Here's the store function and I don't see body_html there?

public function store(Request $request)
    {
        $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'published_at'  => 'required|date',
            'body'          => 'required'
            
        ));
        //create Post
        $post = new Post;
        
        $post->title = $request->title;
        $post->slug = $request->slug;
        $post->category_id = $request->category_id;
        $post->published_at = $request->published_at;
        $post->excerpt = str_limit($request->body, 100);
        $post->body = $request->body;
        $post->author_id = auth()->user()->id;
        
        $post->save();
        
        return redirect('/posts')->with('success', 'Your post created created successfully');
    }
Activity icon

Replied to Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

Not sure what you mean when you say "unformatted text box"?

But here's what I have for you to take look at:

https://i.stack.imgur.com/02JCH.jpg

https://i.stack.imgur.com/e6pvC.jpg

https://i.stack.imgur.com/KNCLR.jpg

--- As I typing this reply ---

Do you mean?

Change {!! $post->body_html !!} to {{post->body_html }}?

when you say "displays in an unformatted text box"?

Activity icon

Replied to Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

Id1 thru 10 were seeded in using php artisan migrate:refresh --seed and I don't have ("p") tags in the raw, but when I create new data using my create form the raw text in my database does have ("p") on in phpMyAdmin and on the site.

Here's my phpMyAdmin... https://i.stack.imgur.com/RBGS9.jpg

Activity icon

Replied to Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

@MANELGAVALDA - @manelgavalda this is my show view...

<article class="post-item post-detail">
                        @if($post->image_url)
                        <div class="post-item-image">
                            <!--{{--<a href="#">--}}-->
                                <img src="{{ $post->image_url }}" alt="{{ $post->title }}">
                            <!-- </a> -->
                        </div>
                        @endif
                        <div class="post-item-body">
                            <div class="padding-10">
                                <h1>{{ $post->title }}</h1>
    
                                    <div class="post-meta no-border">
                                        <ul class="post-meta-group">
                                            <li><i class="fa fa-user"></i><a href="#"> {{$post->author->name}}</a></li>
                                            <li><i class="fa fa-clock-o"></i><time> {{$post->date}}</time></li>
                                            <li><i class="fa fa-tags"></i><a href="/posts/{{$post->category->slug}}"> {{ $post->category->title }}</a></li>
                                            <li><i class="fa fa-comments"></i><a href="#">4 Comments</a></li>
                                        </ul>
                                    </div>
    
                                {!! $post->body_html !!}
                            </div> 
                        </div>
                    </article>
Activity icon

Replied to Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

Here's my create function

public function create()
    {
        $categories = Category::all();
        
        return view('posts.create')->withCategories($categories);
    }

And Here's my store function...

public function store(Request $request)
    {
        $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'published_at'  => 'required|date',
            'body'          => 'required'
            
        ));
        //create Post
        $post = new Post;
        
        $post->title = $request->title;
        $post->slug = $request->slug;
        $post->category_id = $request->category_id;
        $post->published_at = $request->published_at;
        $post->excerpt = str_limit($request->body, 100);
        $post->body = $request->body;
        $post->author_id = auth()->user()->id;
        
        $post->save();
        
        return redirect('/posts')->with('success', 'Your post created created successfully');
Activity icon

Started a new Conversation Body Data Is Including The HTML When It's Input To My PhpMyAdmin...

Here's what I'm talking about ... https://i.stack.imgur.com/4uw9b.jpg

My body form in my create.php textarea has "{!!" at the being and "!!}", I was under the impression that the "{!!" and "!!}" took care of that for me.

create.blade.php

<div class='form-group'>
    {{ Form::label('body', 'Body')}}
    {!! Form::textarea('body', '', ['id' => 'article-ckeditor', 'class' => 'form-control space', 'placeholder' => 'Body Text', 'required' =>'',])!!}
</div>

Need little help, thx...

Jun
19
4 months ago
Activity icon

Replied to How To Get A Excerpt From The Input Data From The Body?

I know I'm asking a few different questions in this discussion... and will stop doing that.

But right now, I wanted to know if you knew "how to fix the way that I'm receiving data now?"...

I think I was the one that deleted the id 01, so I don't think the new posts are replacing the old ones. But what I've noticed is now my new entry are being put on top of the old data.

If you look here: https://i.stack.imgur.com/wmlGt.jpg

You can see that id 14 and 15 have been added on the top of the table and that started after I added your suggestion... $post->excerpt = str_limit($request->body, 100);

I think I might have to refresh my seed sample data and start fresh and try your suggestion?

Activity icon

Started a new Conversation How To Set Up Published_at Form In Laravel 5.8

I have an issue with the published_at showing up when the form is submitted.

So I can layout the view for the form

<div class="form-group">
      {!! Form::label('published_at', 'Publish On:') !!}
      {!! Form::date('published_at', (isset($post) && $post->published_at ? $post->published_at : date('Y-m-d')), ['class' => 'form-control', 'style'=> 'line-height: 19px']) !!}
</div>

But when I submit the data is null... As seen here: https://i.stack.imgur.com/wmlGt.jpg

As I'm typing this post I'm asking myself, "do I need to add the published_at to the validate and make it a "$post->published_at = $request->published_at;" on the store function?" but I'm not sure, that why I'm asking the question to the discussion?

This is what I have right now in the store function...

public function store(Request $request)
    {
        $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'body'          => 'required'
            
        ));
        //create Post
        $post = new Post;
        
        $post->title = $request->title;
        $post->slug = $request->slug;
        $post->category_id = $request->category_id;
        $post->excerpt = str_limit($request->body, 100);
        $post->body = $request->body;
        $post->author_id = auth()->user()->id;
        
        $post->save();
        
        return redirect('/posts')->with('success', 'Your post created created successfully');
    }

I also have a protected $dates = ['published_at']; in my Post model, but Im not sure if this is causing my error?

Here's the Post model just in case you need to see it?

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Carbon\Carbon;
use GrahamCampbell\Markdown\Facades\Markdown;

class Post extends Model
{
    //Table Name
    protected $table = 'posts';
    // Primary Key
    public $primaryKey = 'id';
    // Timestamps
    public $timestamps = true;
    
    protected $fillable = [
        'title',
        'excerpt',
        'body',
        'categery_id',
        'image',
    
    ];
    
    protected $dates = ['published_at'];
    

public function author()
    {
        return $this->belongsTo(User::class);
    }


public function category()
    {
        return $this->belongsTo(Category::class);
    }

public function getImageUrlAttribute($value)
    {
    $imageUrl = "";
    
    if( ! is_null($this->image))
    {
        $imagePath = public_path() . "/img/" . $this->image;
        
        if(file_exists($imagePath)) $imageUrl = asset("img/" . $this->image);
    }
    
    return $imageUrl;
    
    }
    
public function getDateAttribute()
    {
        return is_null($this->published_at) ? '' : $this->published_at->diffForHumans();    
    }

public function getExcerptHtmlAttribute()
    {
        return $this->excerpt ? Markdown::convertToHtml(e($this->excerpt)) : NULL;
    }

public function getBodyHtmlAttribute()
    {
        return $this->body ? Markdown::convertToHtml(e($this->body)) : NULL;
    }

public function scopeLatestFirst($query)
    {
        return $query->orderBy('published_at', 'desc');
    }

public function scopePublished($query)
    {
        return $query->where('published_at', '<=', Carbon::now());
    }

}

Any help would be helpful.

Activity icon

Replied to How To Get A Excerpt From The Input Data From The Body?

That worked, but now the new entry into the data table is being put on top of the old data, but it used to add the new entries at the bottom of the table. Can I fix that? ...

Seen here: https://i.stack.imgur.com/vciG0.jpg

Also... Let me know if I have to begin a new discussion for this one? And My body data is including the HTML when it's input to my phpMyAdmin...

Here's what I'm talking about ... https://i.stack.imgur.com/4uw9b.jpg

My body form in my create.php has "{!!" at the being and "!!}", I was under the impression that the "{!!" and "!!}" care of that for me.

create.blade.php

<div class='form-group'>
        {{ Form::label('body', 'Body')}}
        {!! Form::textarea('body', '', ['id' => 'article-ckeditor', 'class' => 'form-control space', 'placeholder' => 'Body Text', 'required' =>'',])!!}
                                </div>

and here's my store function

public function store(Request $request)
    {
        $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'body'          => 'required'
            
        ));
        //create Post
        $post = new Post;
        
        $post->title = $request->title;
        $post->slug = $request->slug;
        $post->category_id = $request->category_id;
        $post->excerpt = str_limit($request->body, 100);
        $post->body = $request->body;
        $post->author_id = auth()->user()->id;
        
        $post->save();
        
        return redirect('/posts')->with('success', 'Your post created created successfully');
Jun
18
4 months ago
Activity icon

Started a new Conversation How To Get A Excerpt From The Input Data From The Body?

What I want to do is to use the first 100 words that have been inputted from my body input as the excerpt input on my database... I think I need to modify my store function to do this? But I'm not sure how to do that correctly. I looked up the "only" and "except" methods, but I am not sure how it works if I only want the first 100 words of the body input?

This is my store function

public function store(Request $request)
    {
        $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'body'          => 'required'
            
        ));
        //create Post
        $post = new Post;
        
        $post->title = $request->title;
        $post->slug = $request->slug;
        $post->category_id = $request->category_id;
        $post->body = $request->body;
        $post->author_id = auth()->user()->id;
        
        $post->save();
        
        return redirect('/posts')->with('success', 'Your post created created successfully');
    }

and here's my phpMyadmin to excerpt column... https://i.stack.imgur.com/segmG.jpg

Let me know if you need more information from me, to help was this issue...

Jun
15
4 months ago
Activity icon

Replied to Form Select Box {!!Form::select()!!} Laravel 5.8.9

As I said before, your a life saver and I thank you again..

Jun
14
4 months ago
Activity icon

Replied to Form Select Box {!!Form::select()!!} Laravel 5.8.9

I wanted to know if you could look into this new issue that I'm now having. Could you tell me "Why is the ID variable now undefined" in my update function?

This was working before we fixed the other issue...but now not so much...

Here's my update function:

public function update(Request $request)
    {
        /*$updated = Category::findorFail($id);
        $categories = $request->all();
        $category_id = $request->get('category_id');
        $updated->fill($categories)->save();
        
        return redirect('/dashboard')->with('success', 'Your post created updated successfully');*/
        
        $this->validate($request, [
            'title' => 'required|max:255',
            'slug' => 'required|alpha_dash|min:5|max:255',
            'body' => 'required'
            
        ]);
        //create Post
        $post = Post::find($id);
        $post->title        = $request->input('title');
        $post->slug         = $request->input('slug');
        $post->category_id  = $request->input('category_id');
        $post->body         = $request->input('body');
        $post->author_id = auth()->user()->id;
        $post->save();
        
        return redirect('/dashboard')->with('success', 'Your post created updated successfully');

And this is what I get when I try to update the table:

https://i.stack.imgur.com/MaqE1.jpg

And then when I tried to add $post = post::find($id); and replaced the function edit(Post $post) to ($id) :

public function edit($id)
{
    $post = Post::find($id);
    $cats = Category::all()->pluck('title', 'id');
    
            
    // I was talking about this line as a second step for debugging. I see you are using it now.
    return view('posts.edit', compact('post', 'cats')); 
    
}

but I am now getting this e_error and this is what I get when I try to edit: https://i.stack.imgur.com/pFZp1.jpg

Please let me know if I need to open up a new discuss... Thx

Activity icon

Replied to Form Select Box {!!Form::select()!!} Laravel 5.8.9

Great.... that worked! thanks for working with me, you're a real lifesaver...

do you think it could have been the "public function category" in the index function?

public function category(Category $category)
    {
        $categoryName = $category->title;

        $posts = $category->posts()
                           ->with('author')
                           ->latestFirst()
                           ->published()
                            ->paginate($this->limit);
                    
        return view('posts.index', compact('posts', 'categoryName'));
    }

What do you think?

Anyway, things are working now and I "thank you again so very much for all your time and all your help!

Activity icon

Replied to Form Select Box {!!Form::select()!!} Laravel 5.8.9

Yes Sir, this is the right array in my categories table on my DB...

Here's what it looks like... https://i.stack.imgur.com/xpS7h.jpg

Activity icon

Replied to Form Select Box {!!Form::select()!!} Laravel 5.8.9

You say "Try the second step, passing to the view as I gave it to you" do you mean "{!! Form::select('category_id', [ 1 => 'Testing' ], null, ['class' => 'form-control']) !!}"?

If so I'm currently doing and Here's what I have... https://i.stack.imgur.com/L41l1.jpg

I'm very new at Laravel, so I'm not sure how to "debug the array that you get from the categories"?

right now this is what I have in PostController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Post;
use App\Category;
use Session;


class PostsController extends Controller
{
        public function __construct(){
         $this->middleware('auth')->except(['category', 'show']);
        }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
     
    protected $limit = 3;
     
    public function index()
    {
        
        $posts = Post::with('author')
                    ->latestFirst()
                    ->published()
                    ->paginate($this->limit);
                    
        return view('posts.index', compact('posts'));
    }
public function category(Category $category)
    {
        $categoryName = $category->title;

        $posts = $category->posts()
                           ->with('author')
                           ->latestFirst()
                           ->published()
                            ->paginate($this->limit);
                    
        return view('posts.index', compact('posts', 'categoryName'));
    }
    

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $categories = Category::all();
        
        return view('posts.create')->withCategories($categories);
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $this->validate($request, array(
            'title'         => 'required|max:255',
            'slug'          => 'required|alpha_dash|min:5|max:255|unique:posts,slug',
            'category_id'   => 'required|integer',
            'body'          => 'required'
            
        ));
        //create Post
        $post = new Post;
        
        $post->title = $request->title;
        $post->slug = $request->slug;
        $post->category_id = $request->category_id;
        $post->body = $request->body;
        $post->author_id = auth()->user()->id;
        
        $post->save();
        
        return redirect('/posts')->with('success', 'Your post created created successfully');
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(Post $post)
    {   
    
    return view('posts.show', compact('post'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Post $post)
{
    
    //$post = Post::find($id);
    // Check for correct user
        /*if(auth()->user()->id !==$post->author_id){
            return redirect('/posts')->with('error', 'Unauthorized Page');
            }
            
    $post = Post::where('id', $post)
            ->orWhere('slug', $post)
            ->firstOrFail();*/
            
    
    $categories = Category::all()->pluck('title', 'id');
            
    return view('posts.edit', compact('post', 'categories'));
    
}

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request)
    {
        /*$updated = Category::findorFail($id);
        $categories = $request->all();
        $category_id = $request->get('category_id');
        $updated->fill($categories)->save();
        
        return redirect('/dashboard')->with('success', 'Your post created updated successfully');*/
        
        $this->validate($request, [
            'title' => 'required|max:255',
            'slug' => 'required|alpha_dash|min:5|max:255',
            'body' => 'required'
            
        ]);
        //create Post
        $post = Post::find($id);
        $post->title        = $request->input('title');
        $post->slug         = $request->input('slug');
        $post->category_id  = $request->input('category_id');
        $post->body         = $request->input('body');
        $post->author_id = auth()->user()->id;
        $post->save();
        
        return redirect('/dashboard')->with('success', 'Your post created updated successfully');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy(Post $post)
    {
         $posts = Post::with('author');
    
    // Check for correct user
        if(auth()->user()->id !==$post->author_id){
            return redirect('/posts')->with('error', 'Unauthorized Page');
            }
        
        $post->delete();
        
        return redirect('/dashboard')->with('success', 'Your post has been "Delete" successfully');
    }
}

Were do I use the "dd($categories);" that you give me?

Activity icon

Replied to Form Select Box {!!Form::select()!!} Laravel 5.8.9

Ok, so I'm not getting the array anymore but I'm not pluck the 'title' or the "id" from my DB...?

Here's what I have... https://i.stack.imgur.com/L41l1.jpg

Activity icon

Started a new Conversation Form Select Box {!!Form::select()!!} Laravel 5.8.9

I having a few issues with my values not matching up and my dropdown is also giving me the values as an array...

Here's what I have in my PostsController...

public function edit(Post $post)
{
    $categories = Category::pluck('title', 'id');

    return view('posts.edit')->withPost($post)->withCategories($categories);

and here's my edit.blade...

{{ Form::label('category_id', 'Category :')}}
{!! Form::select('category_id', $categories, null, ['class' => 'form-control']) !!}

I have tried the few different ways suggested on other posts, but I'm still having these issues, "need little help"?

Here's the value issue I was talking about: enter image description here- https://i.stack.imgur.com/Ew4j2.jpg

Here's the array issue I was talking about: enter image description here- https://i.stack.imgur.com/RM5kx.jpg

Jun
13
4 months ago
Activity icon

Replied to Form Select Box {!!Form::select()!!}

Like #Ober4You,

I having the same issues with my values not matching up and my dropdown is also giving me the values as an array...

Here's what I have in my PostsController...

public function edit(Post $post)
{
    $categories = Category::all()->pluck('title', 'id')->toArray();

    return view('posts.edit')->withPost($post)->withCategories($categories);

and here's my edit.blade...

{{ Form::label('category_id', 'Category :')}}
{!! Form::select('category_id', $categories, null, ['class' => 'form-control']) !!}

I have tried the few different ways suggested above, but I'm still having these issues, "need little help"?