PT-83

PT-83

Member Since 5 Months Ago

Experience Points
16,870
Total
Experience

3,130 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
146
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 4
16,870 XP
May
23
3 days ago
Activity icon

Replied to Upload Image To Existing Form

Yes, its solved! Thank you so much, this has been a great learning experience for me with your help!

Activity icon

Replied to Upload Image To Existing Form

I think this is it... I opened the broken image link in a separate tab

http://127.0.0.1:8000/posts/uploads/aFnj5O1jSpv3nb.jpeg -> not the right url

http://127.0.0.1:8000/storage/uploads/aFnj5O1jSpv3nb.jpeg -> this is the URL it should be fetching and the image is rendering fine.

May
22
4 days ago
Activity icon

Replied to Upload Image To Existing Form

No luck yet I've tried other variations of code but nothing seems to get the image to load.

This is what I am seeing https://ibb.co/dpZmGDV

I can see the image when I visit http://127.0.0.1:8000/storage/uploads/image_name.jpeg and when I connect to tableplus GUI it is being passed to the table???

May
20
6 days ago
Activity icon

Replied to Upload Image To Existing Form

I used guarded.


namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $guarded = [];
}
Activity icon

Replied to Upload Image To Existing Form

sure, updated original post

Activity icon

Replied to Upload Image To Existing Form

@michaloravec sorry about that. I get null

Activity icon

Replied to Upload Image To Existing Form

Done. I got another error this time Class 'App\Http\Controllers\Storage' not found however I used use Illuminate\Support\Facades\Storage; which solved that (getting used to that)..

Everything is functioning fine but the image is still not being shown. Perhaps something in the form (show.blade.php) fie?

Activity icon

Replied to Upload Image To Existing Form

Class 'App\Http\Controllers\Str' not found @michaloravec by the way you are solid thanks so much for the help so far!!!

error points to $filename = Str::random(14).'.'.request()->image->getClientOriginalExtension()

Activity icon

Replied to Upload Image To Existing Form

Installed... I always get an error this time its Intervention\Image\Exception\NotReadableException Image source not readable image is a jpg.

Activity icon

Replied to Upload Image To Existing Form

@michaloravec I think this is the problem. I just uploaded the photo from my desktop no other installations and not using any program or code like image.intervention.io

But I'm assuming by installing the above it would then function, correct?

Activity icon

Replied to Upload Image To Existing Form

Done. New error Class 'Intervention\Image\Facades\Image' not found

Activity icon

Replied to Upload Image To Existing Form

@michaloravec yes I can. localhost address /storage/uploads/name of file.

Interesting now I submitted the form and got an error (that I didn't get before) the image is still passed but the error is Class 'App\Http\Controllers\Image' not found and it references $image = Image::make(public_path('storage/' . $post->image))->fit(500, 500, null, 'top-left'); code.

Activity icon

Replied to Upload Image To Existing Form

Hi @michaloravec

Yes the image exists in two places.

App/storage/uploads I then create a storage link which makes the file available in public/storage/uploads

Activity icon

Replied to Upload Image To Existing Form

Hi @nishan12 no adding 'uploads' didn't work unfortunately.

Activity icon

Started a new Conversation Upload Image To Existing Form

Hi all, I have successfully added an image file picker to an existing form.

Also, I have php artisan storage:link to access the public/storage/uploads folder which contains the image that was uploaded.

Next step I included an @if statement in my show view to render the image when looking at post details. However, the image is not showing at all in the show view? I am perplexed as to what I'm missing???

PostController

<?php

namespace App\Http\Controllers;

use App\Post;
use Auth;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Storage;
 

class PostController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $posts = Post::all();

        return view('post.index', compact('posts'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $post = new Post();

        return view('post.create', compact ('post'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */

    public function store(Request $request)
    {
        $request->validate([
            'title' => 'required',
            'body' => 'required',
        ]);
        $post = new Post();
        $post->user_id = Auth::user()->id;
        $post->title = $request->title;
        $post->body = $request->body;
        $this->storeImage($post);
        $post->save();


        return redirect('/posts');
    }

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

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Post  $post
     * @return \Illuminate\Http\Response
     */
    public function edit(Post $post)
    {
        return view('post.edit', compact('post'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Post  $post
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Post $post)
    {
        $post->update($this->validatedRequest());

        $this->storeImage($post);

        return redirect('/posts');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Post  $post
     * @return \Illuminate\Http\Response
     */
    public function destroy(Post $post)
    {
        $post->delete();

        return redirect('/posts');
    }

    private function validatedRequest()
    {
        return request()->validate([
            'title' => 'required',
            'body' => 'required',
            'image' => 'sometimes|file|image|max:5000',
        ]);
    }
        
    private function storeImage($post)
    {

        if (request()->has('image')) {
            $filename = Str::random(14).'.'.request()->image->getClientOriginalExtension();
        
            $image = Image::make(request()->image)->fit(500, 500, null, 'top-left')->encode();
        
            Storage::disk('public')->put("uploads/{$filename}", (string) $image);
        
            $post->update([
                'image' => "uploads/{$filename}"
            ]);
        }
    }
}

Form (show.blade.php)

@extends('layouts.app')

@section('content')

<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="pt-3 pl-3 pr-3 card">
                <h1 class="text-secondary">Post Details</h1>

                    <div>
                        <a href="/posts"><- Back</a>
                    </div> 

                    <strong class="text-secondary mt-2">Title</strong>
                         <p>{{ $post->title }}</p>

                    <strong class="text-secondary mt-2">Body</strong>
                        <p>{{ $post->body }}</p>

                @if($post->image)
                    <div class="row">
                        <div class="col-12">
                            <img src="{{ asset('storage/' . $post->image) }}" alt="" class="img-thumbnail">
                        </div>
                    </div>
                @endif

                <div>
                    <a href="/posts/{{ $post->id }}/edit">Edit</a>

                    <form action="/posts/{{ $post->id }}" method="post">
                         @method('DELETE')
                        @csrf

                        <button class="btn btn-danger mt-3 mb-3">Delete</button>  
                    </form>
                </div> 
            </div>
        </div>
    </div>
</div>
@endsection
May
19
1 week ago
Activity icon

Awarded Best Reply on ArgumentCountError Too Few Arguments

Hey all,

I found the issue, at the protected function create(array $data) I was using the wrong instance meaning no data was being sent. So I changed the code like so protected function create(Request $data) which is now working great.

Activity icon

Replied to Where Are You All From?

Toronto, Canada :)

Activity icon

Replied to 500 Server Error Again

Thanks, @sergiu17 !!!

I am also experiencing a server error when I submit the post. I was able to get the upload image file to be visible on the form itself, but once I submit the post it gives me a server 500 again...(bane of my existence). Any idea?

Activity icon

Started a new Conversation 500 Server Error Again

Hi again, I'm sorry for another server error post but I'm not sure what I did to get this error. My create post form was working fine until I tried to add a new field "image" upload to the form. Now when I visit the /posts/create page I get a server error 500.

Any idea why this is occurring?

web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Mail\WelcomeMail;

Route::group(['middleware' => 'web'], function () {
    Route::auth();

    Route::get('/', function () {
        return view('welcome');
    });

Route::get('/home', '[email protected]');
});

Route::get('/about', function () {
    return view('about');
}); 

Route::get('/email', function () {
    return new WelcomeMail();
});

Auth::routes();

Route::get('/posts', '[email protected]');
Route::get('/posts/create', '[email protected]');
Route::post('/posts/create', '[email protected]');
Route::get('/posts/{post}', '[email protected]');
Route::get('/posts/{post}/edit', '[email protected]');
Route::patch('/posts/{post}', '[email protected]');
Route::delete('/posts/{post}', '[email protected]');

Route::post('/register', 'Auth\[email protected]')->name('register');

Route::get('/contact', '[email protected]');
Route::post('/contact', '[email protected]');

Form

<div class="container">
    <div class="row justify-content-cemter">
       <div class="col-md-8">
           <div class="card">
               <div class="card-header">Create New Post</div>


                <div class="card-body">
                    <form action="/posts/create" method="POST" enctype="multipart/form-data">


                        @csrf

                        <div class="form-group">
                            <label for="title">Title</label>
                            <input name="title" type="text" class="form-control" id="title" aria-describedby="titleHelp" placeholder="Enter Title" autocomplete="off">
                            <small id="titleHelp" class="form-text text-muted">Give your post a title that will describe your post easily</small>
                        </div>

                        <div class="form-group">
                            <label for="body">Body</label>
                            <textarea type="text" name="body" cols="30" rows="3" class="form-control" id="body" aria-describedby="bodyHelp" placeholder="Enter Post Body" autocomplete="off"></textarea>
                             <small id="bodyHelp" class="form-text text-muted">Enter as much detail you'd like!</small>
                        </div>

                        <div class="form-group d-flex flex-column">
                            <label for="image">Image</label>
                            <input type="file" name="image" class="py-2">
                        <div>{{ errors->first('image') }}</div>
                        </div>

                        <button type="submit" class="btn btn-primary">Create Post</button>

                        @if (session('message'))

                            <div>
                                {{ session('message') }}
                            </div>
                        @endif

                    </form>

                    @if ($errors->any())
                        <div class="alert alert-danger mt-5">
                            <ul>
                     @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                    @endforeach
                            </ul>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>

migration


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id');
            $table->string('title');
            $table->longText('body');
            $table->string('image')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}
Activity icon

Replied to ArgumentCountError Too Few Arguments

Hey all,

I found the issue, at the protected function create(array $data) I was using the wrong instance meaning no data was being sent. So I changed the code like so protected function create(Request $data) which is now working great.

May
18
1 week ago
Activity icon

Started a new Conversation ArgumentCountError Too Few Arguments

Hi all,

On localhost when I try to register a new user I get this error "ArgumentCountError Too few arguments to function App\Http\Controllers\Auth\RegisterController::create(), 0 passed and exactly 1 expected".

However, I am not entirely sure why it's throwing this error. Hoping for some guidance on this one (like many others..) The RegisterController is the default when installing in Laravel.

I should note in production I can register no problem just on localhost it gives me the too few arguments error. I want to test new features on localhost prior to making it to production.

Web.php

<?php

use Illuminate\Support\Facades\Route;
use App\Mail\WelcomeMail;

Route::group(['middleware' => 'web'], function () {
    Route::auth();

    Route::get('/', function () {
        return view('welcome');
    });

Route::get('/home', '[email protected]');
});

Route::get('/about', function () {
    return view('about');
}); 

Route::get('/email', function () {
    return new WelcomeMail();
});

Auth::routes();

Route::get('/posts', '[email protected]');
Route::get('/posts/create', '[email protected]');
Route::post('/posts/create', '[email protected]');
Route::get('/posts/{post}', '[email protected]');
Route::get('/posts/{post}/edit', '[email protected]');
Route::patch('/posts/{post}', '[email protected]');
Route::delete('/posts/{post}', 'PostCont[email protected]');

Route::post('/register', 'Auth\[email protected]')->name('register');

Route::get('/contact', '[email protected]');
Route::post('/contact', '[email protected]');

RegisterController


namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = RouteServiceProvider::HOME;

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
        ]);
    }
}
Activity icon

Started a new Conversation One To One, And One To Many Relationships?

Hello,

In my web application, when I create a post, it can be seen by other users. Therefore, each user can see other user's posts.

In order to have the users post only visible to themselves, would it make sense to create a 'user can have many posts' but 'a post can only have one user' relationship? Would that be done by using eloquent?

Also, the next step would be if the user would like the post to become public, that can simply click share and it would be visible to all.

How would I be able to accomplish the above? any resources I can look into or video lessons, etc?

thanks in advance.

May
09
2 weeks ago
Activity icon

Replied to Integrating Mail-chimp API In Laravel

Thanks I'll take a look!!

Activity icon

Started a new Conversation Integrating Mail-chimp API In Laravel

Hey all,

As the title suggests is there a resource or can you point me in the right direction on how to correctly set up a Mailchimp API?

I have zero experience doing this but I need to get it implemented in my application as there are users signing up, but I have no way to respond currently (other than manually adding the users to a list).

Thanks in advance.

May
06
2 weeks ago
Activity icon

Replied to Php Returning Empty Array?

Hi all, thanks for your assistance. I am not sure what I did wrong here, but I moved on with the tutorial lesson and got it to work with different data. I did tinker with localhost which could have solved the issue also.

Consider this closed.

Thank you all.

May
05
3 weeks ago
Activity icon

Replied to Php Returning Empty Array?

I tried but nothing the same things occur. The bulleted list with no data from the array being passed. I have a funny feeling this is a localhost issue on my end. I will try and diagnose and see what I can come up with.

Activity icon

Replied to Php Returning Empty Array?

@james_moore after var_dump nothing is happening and the 4 bullet list is still showing with no additional data. Also I noticed this on localhost Closed without sending a request; it was probably just an unused speculative preconnection not sure if that's causing an issue.

I also edited the <?= $key; ?> to use <?php tags instead

Activity icon

Replied to Php Returning Empty Array?

Hi @james_moore, I am getting the bullet list also but the problem is it's not passing the array data to the list for some reason.

Activity icon

Replied to Php Returning Empty Array?

@michaloravec unfortunately, it's still showing a bullet but with no data from the array.

Activity icon

Started a new Conversation Php Returning Empty Array?

Following along in the php series there's homework about arrays.

When I run the code (that's replicated from the video) it's outputting an empty array, not sure why that's happening? Any idea what im doing wrong?

index.php

<?php


$person = [
    'age' => 31,
    'height' => 5,
    'profession' => 'unkown'
];

require 'index.view.php'; 

index.view.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <ul>    

        <?php foreach ($person as $key => $feature) : ?>

            <li><strong><?= $key; ?></strong> <?= $feature; ?></li>

        <?php endforeach; ?>

    </ul>
    
</body>
</html>
May
04
3 weeks ago
Activity icon

Commented on Step 7: Associative Arrays

When I run the code is outputting an empty array, not sure why that's happening? Any idea what im doing wrong?

index.php

<?php


$person = [
    'age' => 31,
    'height' => 5,
    'profession' => 'unkown'
];

require 'index.view.php'; 

index.view.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <ul>    

        <?php foreach ($person as $key => $feature) : ?>

            <li><strong><?= $key; ?></strong> <?= $feature; ?></li>

        <?php endforeach; ?>

    </ul>
    
</body>
</html>
Activity icon

Started a new Conversation I Love Laravel But I Am Not Understanding All The Concepts Etc

I have dabbled in code like completing the css/html on freecode camp. I have touched javascript but really don't remember much.

I love Laravel as it supplies so much out of the box, but when watching videos like building an app for instance there is a lot of things going on I don't necessarily understand, which I think is limiting my coding to very basic concepts. To give you an example, when I see something like this; $this->get($post)->where()->auth() return, etc.. I really don't understand what exactly is happening here.

My question is what resource should I be looking at to really grasp these concepts? Should I begin with PHP then move to Laravel at that point? What are good resources to look at?

I stated laravel learn the basics and began with laravel 6 start from scratch series, is that a good place to start?

Thanks for your help

May
01
3 weeks ago
Activity icon

Replied to Email Service

According to Mailguns site, the free tier is still available, "Try us out! Get 5,000 free emails per month for 3 months, then only pay for what you send" if I'm understanding this correctly, after the trial period you can still send 1000 emails for free but 0.80 per email afterward.

Are there any other good options?

Activity icon

Replied to Footer That Stays At The Bottom?

@michaloravec Works but it covers the CTA button on the homepage.

Activity icon

Started a new Conversation Footer That Stays At The Bottom?

Hi all,

I have tried multiple times to get the footer to stay at the bottom of the page, however on certain pages when the content is short or contains a form only the footer tends to rise up and sit underneath the content or form.

example of the footer rising up - https://famijam.com/register

How can I make sure the footer stays at the bottom?

<footer id="footer">
    <div class="container-fluid h-100 bg-white">
        <div class="row h-100 ">
            <div class="col mt-3 mb-3 d-flex justify-content-center align-items-center">
                <a href="https://famijam.com" class="m-2">
                    <i class="fas fa-globe"></i></a>
                <a href="https://twitter.com/p_trulli" class=" m-2">
                    <i class="fab fa-twitter"></i></a>
                <a href="https://github.com/PT-83" class="m-2">
                    <i class="fab fa-github"></i></a>

                <small class="justify-content-center m-2"> &copy;  2020, FamiJam</small>
            </div>
          </div>
        </div>
</footer>

Apr
29
3 weeks ago
Activity icon

Replied to Images Not Loading On Server 404 Error

@michaloravec Thank you so much, you have been a great help on many subjects!!!

Activity icon

Started a new Conversation Images Not Loading On Server 404 Error

Hi all,

I had a similar issue in the past, the css/app.css was not loading images. The issue was my css was capitalized 'CSS' but not capitalized in the <link>. Once adjusted the images loaded correctly.

This time I made sure to name both the directory and <link> in lower case 'css' but the images are not loading again :(

When I inspect in chrome I am seeing the following error Failed to load resource: the server responded with a status of 404 () image name sample.svg:1 This is occurring for all photos.

Also, strangely I have an SVG logo in my header that loads correctly in all pages except one, which is broken, I have no idea why that is.

Anyhow I will post my code below any direction or suggestions would be appreciated.

https://famijam.com

app.layout

<!doctype html>
<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', 'Famijam') }}</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">
</head>
<body>
    <div id="app">
        <nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
            <div class="container">
                <a href="/"><img src="/images/FamiJam.svg"></a>
                <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
                    <span class="navbar-toggler-icon"></span>
                </button>

                <div class="collapse navbar-collapse" id="navbarSupportedContent">
                    <!-- Left Side Of Navbar -->
                    <ul class="navbar-nav mr-auto">
                        <li class="nav-item">
                            <a class="nav-link" href="/about">About</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/contact">Contact</a>
                        </li>
                    </ul>

                    <!-- Right Side Of Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <!-- Authentication Links -->
                        @guest
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
                            </li>
                            @if (Route::has('register'))
                            <li class="nav-item">
                                <a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
                                </li>
                            @endif
                        @else
                            <li class="nav-item dropdown">
                                <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                                    {{ Auth::user()->name }} <span class="caret"></span>
                                </a>

                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
                                    <a class="dropdown-item" href="posts/create">Create Post</a>
                                    <a class="dropdown-item" href="/posts">All Posts</a>
                                    
                                    <a class="dropdown-item" href="{{ route('logout') }}"
                                       onclick="event.preventDefault();
                                                     document.getElementById('logout-form').submit();">
                                        {{ __('Logout') }}</a>

                                    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
                                        @csrf
                                    </form>
                                </div>
                            </li>
                        @endguest
                    </ul>
                </div>
            </div>
        </nav>

        <main class="py-4">
            @yield('content')
        </main>
    </div>
</body>
</html>

<footer class="footer">
    <div class="container-fluid h-100 bg-white">
        <div class="row h-100 ">
            <div class="col mt-3 mb-3 d-flex justify-content-center align-items-center">
                <a href="https://famijam.com" class="m-2">
                    <i class="fas fa-globe"></i></a>
                <a href="https://twitter.com/p_trulli" class=" m-2">
                    <i class="fab fa-twitter"></i></a>
                <a href="https://github.com/PT-83" class="m-2">
                    <i class="fab fa-github"></i></a>

                <small class="justify-content-center m-2"> &copy;  2020, FamiJam</small>
            </div>
          </div>
        </div>
</footer>

Welcome page


@extends('layouts.app')

@section('content')

<div class="container h-100">
    <div class="row h-100 justify-content-center align-items-center">
        <div class="col">
            <h1 class="mb-3 text-center display-3 text-secondary">Document Family Traditions</h1> 
        </div>
    </div>

<div class="container h-100">
    <div class="row h-100 justify-content-center align-items-center">
        <div class="col">
            <h3 class="mt-3 text-secondary">Family is important, and so are the many experiences we want to remember! Welcome to Famijam. A place to document any family tradition or memory!!! </h3>
        </div>
    <div class="col text-center">
        <img src="/images/love.svg" class="img-fluid" alt="Responsive image">
    </div>
</div>

<div class="container h-100">
    <div class="row h-100 justify-content-center align-items-center">
    <div class="col text-center">
        <img src="/images/fun.svg" class="img-fluid" alt="Responsive image">
    </div>
    <div class="col"> 
        <h3 class="mt-3 text-secondary">Why is this important you ask? Simply. Family won't be around forever, what better than to document things you don't want to forget, so when desired you can reflect back at that funny moment, family photographs or to show your kids or grandkids! </h3>
    </div>
</div>

<div class="container h-100">
    <div class="row h-100 justify-content-center align-items-center">
        <div class="col">
            <h3 class="mt-3 text-secondary">What kind of things should you submit? Our answer, anything you desire. Homemade recipes, favourite jokes, stories, experiences photographs and alike.
            </h3>
                    </div>
                <div class="col text-center">
            <img src="/images/photo.svg" class="img-fluid" alt="Responsive image">
        </div>
    </div>
</div>

<div class="container h-100 mt-5">
    <div class="row h-100 justify-content-center align-items-center">
        <div class="col-6">

            <h2 class="d-flex">Ready to Join?</h2> 
            <h2 class="text-primary"> Start By Signing Up </h2>

            <a class=" mt-3 btn btn-primary btn-lg btn-block" href="/register" role="button">Sign Up</a>
        </div>
    </div>
</div>

@endsection

Activity icon

Awarded Best Reply on Server 500 Upon Form Submission

Ok, this is working now but it may not the best way.

Added Route::post('/register', 'Auth\[email protected]')->name('register'); to the web.php file,

Added protected function create(Request $request) { User::create($request->all()); return redirect('/home'); } to the RegistrationController.

That's it, it now passes data through to the database.

Activity icon

Replied to Create Post Form Data Not Submitting To Database?

@jlrdw thanks! I have edited the store function, I believe correctly.

Edit* - I have discovered my issue. In the form, I forgot to include name="body" so it was not seeing the inputted text. By including the name"" the form is now passing the data to the database!

Apr
28
4 weeks ago
Activity icon

Replied to Create Post Form Data Not Submitting To Database?

@jlrdw I did try adding Request $request to the store function in the controller but still noting is passed through.

Activity icon

Replied to Create Post Form Data Not Submitting To Database?

Not that I see. The form just refreshes. I tried to dd($data) I got a 500Server error

Activity icon

Started a new Conversation Create Post Form Data Not Submitting To Database?

Hi all, I once again am having a hard time with another form submission. I have tried to replicate past questions regarding this issue, but nothing seems to work. I may be missing a small detail but I cannot figure this out. I am hoping for help again.

Webphp

Auth::routes();

Route::get('/posts', '[email protected]');
Route::get('/posts/create', '[email protected]');
Route::post('/posts/create', '[email protected]');
Route::get('/posts/{post}', '[email protected]');
Route::get('/posts/{post}/edit', '[email protected]');
Route::patch('/posts/{post}', '[email protected]');
Route::delete('/posts/{post}', '[email protected]');

Route::post('/register', 'Auth\[email protected]')->name('register');

Route::get('/contact', '[email protected]');
Route::post('/contact', '[email protected]');

PostController


namespace App\Http\Controllers;
use App\Post;
use Illuminate\Http\Request;

class PostController extends Controller
{
    public function __construct()
    {
        $this->middleware('auth');
    }

    public function index()
    {
        $posts = Post::all();

        return view('post.index', compact('posts'));
    }

    public function create()
    {
        $post = new Post();

        return view('post.create', compact ('post'));
    }

    public function store(Request $request)
    {
        $data = request()->validate([
            'title' => 'required',
            'body' => 'required'
        ]);

        $post = \App\Post::create($data);

        return redirect('/posts');
    }

    public function show(Post $post)
    {
        return view('post.show', compact('post'));
    }

    public function edit(Post $post)
    {
        return view('post.edit', compact('post'));
    }

    public function update(Post $post)
    {
        $post->update($this->validatedData());

        return \redirect('/posts');
    }
    
    public function destroy(Post $post)
    {
        $post->delete();

        return redirect('/posts');
    }

    protected function validatedData()
    {
        return request()->validate([
            'title' => 'required',
            'body' => 'required'
            //'photograph'=> nullable
            //'gif'=> nullable
        ]);
    }
}

Migration


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('title');
            $table->longText('body');
            // $table->#('photograph');
             // $table->#('gif');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}

Post Form

    <div class="row justify-content-cemter">
       <div class="col-md-8">
           <div class="card">
               <div class="card-header">Create New Post</div>


                <div class="card-body">
                    <form action="/posts/create" method="post">

                        @csrf

                        <div class="form-group">
                            <label for="title">Title</label>
                            <input name="title" type="text" class="form-control" id="title" aria-describedby="titleHelp" placeholder="Enter Title" autocomplete="off">
                            <small id="titleHelp" class="form-text text-muted">Give your post a title that will describe your post easily</small>
                        </div>

                        <div class="form-group">
                            <label for="body">Body</label>
                            <textarea type="text" cols="30" rows="3" class="form-control" id="body" aria-describedby="bodyHelp" placeholder="Enter Post Body" autocomplete="off"></textarea>
                             <small id="bodyHelp" class="form-text text-muted">Enter as much detail you'd like!</small>
                        </div>

                        <button type="submit" class="btn btn-primary">Create Post</button>

                    </form>

                    @if ($errors->any())
                        <div class="alert alert-danger mt-5">
                            <ul>
                     @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                    @endforeach
                            </ul>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>

Post Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    protected $guarded = [];
}

Activity icon

Replied to Contact Form Not Passing Data To Database?

                            <label for="text">Text</label>
                            <textarea type="text" class="form-control" id="text" cols="30" rows="3" aria-describedby="textHelp" placeholder="Message" autocomplete="off" value="">
                        </div>

That's how I added the textarea. It seems my footer is now gone and half the code is in the text box...yikes Maybe a footer code issue?

Activity icon

Replied to Contact Form Not Passing Data To Database?

Ahh ok, that might be it ill try that. * That was it... thank you so much!

Something strange happens when I use <textarea> Inside the text box some code is showing up?

</div>

                     <input type="hidden" name="_token" value="VGJedWqRNuLpsCXzNT4lNY9mHR0fC5qZDLxy1msb">
                     <button type="submit" class="btn btn-primary">Submit</button>
                 </form>
             </div>
         </div>
     </div>
 </div>
</div>
     </main>
 </div>
</body>
</html>

<footer class="footer">
 <div class="container-fluid h-100 bg-white">
     <div class="row h-100 ">
         <div class="col mt-3 mb-3 d-flex justify-content-center align-items-center">
             <a href="https://famijam.com" class="m-2">
                 <i class="fas fa-globe"></i></a>
             <a href="https://twitter.com/p_trulli" class=" m-2">
                 <i class="fab fa-twitter"></i></a>
             <a href="https://github.com/PT-83" class="m-2">
                 <i class="fab fa-github"></i></a>

             <small class="justify-content-center m-2"> ©  2020, FamiJam</small>
         </div>
       </div>
     </div>
</footer>
Activity icon

Replied to Contact Form Not Passing Data To Database?

ok, thanks. If I am understanding what your asking, I entered test (as the name) [email protected] (as the email) and testing (as the text) then hit submit.

Activity icon

Replied to Contact Form Not Passing Data To Database?

@michaloravec Are you referring to the inputs inside the form?

From the form - Also posted above;

<input name="name" type="text"
 <input name="email" type="email"
<input name="text" type="text"
Activity icon

Replied to Contact Form Not Passing Data To Database?

Ok @michaloravec , sorry about that. I posted the code hit submit in the form and the form just refreshed, no dd data was outputted.

Activity icon

Replied to Contact Form Not Passing Data To Database?

Hi @michaloravec,

yes data is being passed when $dd (request->all()); Shows an array with the id, name, email, and text.