Our Black Friday sale is now live! All individual subscriptions are 50% OFF. This week only!

Alex_B

Alex_B

Member Since 5 Months Ago

Experience Points
2,700
Total
Experience

2,300 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
14
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 1
2,700 XP
Oct
01
1 month ago
Activity icon

Started a new Conversation The Goodbye Debacle - PODCAST

Not sure if Jeff reads these or not, but anyone that listened to the podcast will know what I'm talking about. Jokes will always manage to offend someone. That's what I've heard every professional comic say about their material. Some jokes can go too far, but this isn't one of those cases. I don't think the goodbye page should be changed because some people didn't get it and took it the wrong way. It's funny and I'm done wasting my time on it. What do you guys think?

Sep
22
2 months ago
Activity icon

Replied to SQLSTATE[23502]: Not Null Violation: 7 ERROR: Null Value In Column "user_id" Violates Not-null Constraint

yes I used fillable.

protected $fillable = ['user_id', 'module' , 'current', 'completed'];
Activity icon

Started a new Conversation SQLSTATE[23502]: Not Null Violation: 7 ERROR: Null Value In Column "user_id" Violates Not-null Constraint

I'm trying to create an entry in another table when a new user registers. I put this in my RegisterController

protected function create(array $data)
    {
        $user = User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'dob' => $data['dob'],
        ]);

        Season::create([
            'user_id', $user->id,
            'module', 0,
            'current', 0,
            'completed', 0,
        ]);

        return $user;
    }

Here's my table migration

    public function up()
    {
        Schema::create('seasons', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
            $table->foreignId('user_id')->constrained();
            $table->integer('module');
            $table->integer('current');
            $table->integer('completed');
        });
    }

I'm using postgres and for some reason it's telling me that my $user->id is passing null. What am I doing wrong here?

Here's the complete error message.

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "user_id" violates not-null constraint DETAIL: Failing row contains (1, 2020-09-22 18:44:21, 2020-09-22 18:44:21, null, null, null, null). (SQL: insert into "seasons" ("updated_at", "created_at") values (2020-09-22 18:44:21, 2020-09-22 18:44:21) returning "id") 
Aug
10
3 months ago
Activity icon

Replied to Performing A Search HasMany And BelongsTo Relation

Thank you, I wish I saw your reply sooner. How can I limit the query so it only returns results if items exist or more specifically in my case if both items and categories have data in them. Something like this

SELECT * FROM Customer customer, Item item, Category category WHERE customer.name LIKE %serarch% AND customer.id = item.customer_id AND item.id = category.item_id;

edit: I figured it out just had to do this

$customers = Customer::search($data['q'])->with('items.categories')->has('items')->get();
Activity icon

Replied to Performing A Search HasMany And BelongsTo Relation

My relations are like this

Customer hasMany Items
Items belongsTo Customer 
Item hasMany Categories
Categories belongsTo Item.

so I did this

$customers = Customer::search($data['q'])->with('items.categories')->get();

Thanks, I found it under Nested Eager Loading. This works and gets me everything, but how can I limit it to only load data if there are items or categories too?

Aug
09
3 months ago
Activity icon

Started a new Conversation Performing A Search HasMany And BelongsTo Relation

I'm trying to make a search option, but i'm having some problems. For example I have a scopeSearch I'm using that will

return $query->where('name', 'LIKE', "%$search%");

and works fine. So when I do

$customers = Customer::search($data['query'])->get();

I'm able to get the names of all customers and iterate them in my view. What I would like to do is something similar for another table that's linked to it, but for some reason it's not working. The other table is Item which has a customer_id foreign key. I'm trying to do a

foreach($customers as $customer)  
$items = Item::where('customer_id', $customer->id); 

When I do dd($items) all I see is #items: [] so I'm not getting any results. If I use ->get() or ->first() I get null or empty results again.

What am I doing wrong here?

edit:

Customer hasMany Item.

solution is to use eloquent like this:

$customers = Customer::search($data['q'])->with('items.categories')->has('items')->get();

Thank you everyone for your help!

Aug
04
3 months ago
Activity icon

Replied to Password Authentication Failed For User "postgres"

Yes, but it's ok I'll just use the stackoverflow solution.

Jul
31
3 months ago
Activity icon

Replied to Password Authentication Failed For User "postgres"

I saw that post too, and not using a password for it doesn't work either. Thanks anyway.

Activity icon

Started a new Conversation Password Authentication Failed For User "postgres"

This is my first time using postgres so I'm a little confused how to setup the connection here.

I installed postgres on Ubuntu from terminal with sudo apt install postgresql postgresql-contrib and I am able get into it using sudo -i -u postgres. I put this into my .env file

DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=postgres
DB_USERNAME=postgres
DB_PASSWORD=postgres

and I'm getting the authentication error. I tried putting my root password in there as well, but that didn't change anything. What did I do wrong here?

complete error for reference :

php artisan migrate

   Illuminate\Database\QueryException 

  SQLSTATE[08006] [7] FATAL:  password authentication failed for user "postgres"
FATAL:  password authentication failed for user "postgres" (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +34 vendor frames 
  35  artisan:37
      Illuminate\Foundation\Console\Kernel::handle()

Jul
22
4 months ago
Activity icon

Started a new Conversation Search Multiple Models Based On One Query From A Model's Scoped Search

I'm trying to implement a string search for one table that is daisy chained to other tables. It should be able to get any value if it exists from any of those tables. I have a customer, invoice, order models/tables. Customer has a fk inside of Invoice and Invoice has a fk inside of Order. So they all have a one-to-many relationship going down the list. For example I search for a customer by name and I would like to be able to get all of that customer's invoices and all of the orders that belong to those invoices.

Here is my Customer model:

class Customer extends Model
{
    use SoftDeletes;
    protected $guarded = [];

    public function scopeSearch($query, $search)
    {
        return $query->where('internal_name', 'LIKE', "%$search%")
            ->orderBy('created_at', 'desc');
    }

    public function invoices()
    {
        return $this->hasMany(Invoice::class);
    }
}

Invoice and order models:

class Invoice extends Model
{
    use softDeletes;

    public function customer()
    {
        return $this->belongsTo(Customer::class);
    }

    public function orders()
    {
        return $this->hasMany(Order::class);
    }
}
class Order extends Model
{
    use SoftDeletes;

    public function invoice()
    {
        return $this->belongsTo(Invoice::class);
    }
}

here is my controller method:

// check if query exists and sanitize it
        if($request->has('q') && $data = $this->sanitizeQuery($request))
        {
            $customers = Customer::with('invoices')->search($data['q'])->get();
            dd($customers);

for the output i get this:

Illuminate\Database\Eloquent\Collection {#1235 ▼
  #items: array:23 [▼
    0 => App\Customer {#1253 ▶}
    1 => App\Customer {#1254 ▶}
    2 => App\Customer {#1255 ▶}
    3 => App\Customer {#1256 ▶}
    4 => App\Customer {#1257 ▶}
    5 => App\Customer {#1258 ▶}
    6 => App\Customer {#1259 ▶}
    7 => App\Customer {#1260 ▶}
    8 => App\Customer {#1261 ▶}
    9 => App\Customer {#1262 ▼
      #guarded: []
      #connection: "mysql"
      #table: "customers"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:14 [▶]
      #original: array:14 [▶]
      #changes: []
      #casts: []
      #classCastCache: []
      #dates: array:1 [▶]
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "invoices" => Illuminate\Database\Eloquent\Collection {#1224 ▼
          #items: []
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #forceDeleting: false
    }

I see that there is an empty invoice there, but I have a row in my db with the matching customer_id. How can I get this data and how can I extend this to work for the orders as well?

Jul
21
4 months ago
Activity icon

Replied to Where Are You All From?

New York City

Jul
14
4 months ago
Activity icon

Replied to Simple Fade Out Component With Vue Js In Laravel

I changed it to this

<style>
    .fade-enter-active, .fade-leave-active {
        transition: opacity 2.5s ease-out;
    }
    .fade-enter, .fade-leave-to {
        opacity: 0;
    }
</style>

<template>
    <div>
        <transition name="fade">
            <div class="alert alert-success" role="alert" v-if="show">
                <strong>Success.</strong> {{message}}
            </div>
        </transition>
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        },
        props : ['message'],
        show : true,
    }
</script>

but now it doesn't show up at all.

Activity icon

Started a new Conversation Simple Fade Out Component With Vue Js In Laravel

Hey guys, I'm trying to figure out some of the basics here and I'm stuck. I'm using laravel 7.x and vue 2.x I made my flashMessage.vue component like so:

<template>
    <div>
        <transition name="fade">
            <div class="alert alert-success" role="alert">
                <strong>Success.</strong> {{message}}
            </div>
        </transition>
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        },
        props : ['message'],
        data : ['show']
    }
</script>

My app.js contains the right info too

Vue.component('flash-message', require('./components/flashMessage.vue').default);

What I want to do is flash this message and have it fade out after 0.5 sec. I added the following to my app.css

    .fade-enter-active, .fade-leave-active {
        transition: opacity .5s;
    }
    .fade-enter, .fade-leave-to {
        opacity: 0;
    }

than in my blade I have an if statement to display this component when I get a session message

@if(session()->has('message'))
    <flash-message message="{{session()->get('message')}}"></flash-message>
@endif

Everything is working, but how do I connect the css to the component to actually get it to fade out?

Jul
13
4 months ago
Activity icon

Replied to Call If Statement Inside If Statement

what error message are you getting?

Activity icon

Started a new Conversation Missing Resources/js/components Directory In Laravel 7

I'm trying to follow some tutorials and I notice that I'm missing this resources/js/components directory. I checked the docs and it says it should be there from the Laravel/ui package, but it's not and I did use composer require laravel/ui and php artisan ui bootstrap --auth when making this project. When I search for my ExampleComponent.vue file it's located in vendor/laravel/ui/src/Presets/vue-stubs/ExampleComponent.vue. Does anyone else have this issue? Did I break something? Was it moved because I used php artisan ui bootstrap --auth ?

Activity icon

Replied to Search Product By A Category Id In Laravel

Something like this?

        if($request->get('search-category')) {
            $search = $request->get('search-category');
            $products = Product::join('product_category', 'product.id', '=', 'product_category.product_id')
                ->join('category', 'category.id', '=', 'product_category.category_id')->where('column_name','LIKE',"%$search%")
                ->select('product.id', 'product.title', 'product.description', 'product.price')
                ->get();
        }
        return view('search', compact('products'));
Activity icon

Replied to Get Value Of Object From Foreach Array?

Where is it returning like an object? It's returning an ordered map. Every array has a $value to $keys association.

Activity icon

Replied to Best Practices - Redirect A Page After Some Time Has Passed

Oh okay I get it now. Between both your answers you guys filled in a lot of gaps for me. Thanks for the explanations guys, sorry if I did not make the question so clear. Hopefully I'll be as knowledgeable as you guys some day and can contribute back to the community too!

To summarize, I want to avoid the meta tag redirects like @martinbean mentioned (at least for now) and I can do a 5 second message like @snapey mentioned.

Activity icon

Replied to Best Practices - Redirect A Page After Some Time Has Passed

What's the best way to redirect a user without them doing anything on the page. As I mentioned before I've seen php sites that try to redirect, but something fails in the request cycle and the redirect doesn't work. I guess I'm answering my own question here, but it would be best to use javascript to perform the redirect since it would be executed client side and could trigger the request cycle automagically on the server side. How would you handle doing a redirect without anything being done by the user?

Activity icon

Replied to Best Practices - Redirect A Page After Some Time Has Passed

That redirect just shows a message, but lets say I want to do another redirect without the user doing anything at that point. So I want them to see the message that everything worked, but than I want to redirect them to their previous page before they submitted anything. What would you suggest is the best approach to handle it?

Activity icon

Started a new Conversation Best Practices - Redirect A Page After Some Time Has Passed

Objective: redirect a page after 3 seconds.

Context: user submits input, gets a return redirect('/')->with('message', 'Success!');

I've searched online and have seen all sorts of solutions to this problem. A lot of people seem to favor doing a redirect using Javascript. Others suggest just using sleep() method with laravel. Seems like either one of these would be fine. I want to know what you guys think is best practice for this situation. Have you ever had problems using either one of those before?

For example I notice some websites will say Redirecting in 5 seconds... click here if it fails. Sometimes it does fail and since I don't know how they are redirecting, I would like to avoid that situation with my web app.

Jul
12
4 months ago
Activity icon

Replied to Microsoft Ending Support For PHP After 8.0

Thanks @snapey and @jlrdw .

We’re still in initial reaction phase here, but the bottom line is there will likely be very little change for Windows > users.

That pretty much sums it up.

Activity icon

Started a new Conversation Microsoft Ending Support For PHP After 8.0

I recently read this in a news feed https://externals.io/message/110907. I'm not familiar with any of this, but what kind of support was Microsoft even giving? Can someone put this into layman's terms for me? I'm running all my stuff on Linux so I don't see how this would impact my app, would it?

Jul
11
4 months ago
Activity icon

Started a new Conversation Pros And Cons Between Laravel Versions

I'm new to Laravel and so far it's been great. One thing I noticed is that different version of laravel can break stuff. How do you manage the switch from one version of Laravel to the other? Are new version of Laravel backwards compatible? What are some things to consider when deciding to change version or pick a version to use for the first time? Since I'm new and starting out I decided to pick v7.16 and the only draw back to it is the lack of tutorials. Should I always strive to use the latest version of Laravel?

Jul
10
4 months ago
Activity icon

Replied to Laravel Blade How To Get Default Value Or Old/new Value In Select Option List

that worked thank you!

<select id="inputState" name="inputState" class="form-control">
        @foreach($states as $key => $value)
            <option value="{{$key}}" 
                {{old('inputState', 'NY') == $key ? 'selected' : ''}}>{{$value}}
            </option>
        @endforeach
    </select>
Activity icon

Started a new Conversation Laravel Blade How To Get Default Value Or Old/new Value In Select Option List

I have a drop down list for states. I want the list to default on a specific state so the user won't have to select it each time, but I want to be able to get the old value in case they change it.

    <select id="inputState" name="inputState" class="form-control">
        @foreach($states as $key => $value)
            <option value="{{$key}}"
            {{$key == 'NY' ? 'selected' : ''}}>{{$value}}
            </option>
        @endforeach
    </select>

This will default to New York. If user changes the state and the form didn't get validated I want to be able to return the changed state. So if they select New Mexico it should return that instead of New York. Can anyone help me with this?

Activity icon

Replied to Anyway To Fix Request()->validate Error: Array_map():Expected Parameter 2 To Be An Array, Int Given

This isn't really the way I wanted to do it, but this sort of solves it for me.

    private function validateRequest()
    {
        return request()->validate([
            'name' => 'required|min:3',
            'role_id' => 'digits:1',
        ]);
    }

This will at least make sure it's a single int value and I can compare the values in another method. I was trying to see if it's possible to do this all in one go using validate instead of doing it in two places, but this works too.

Jul
09
4 months ago
Activity icon

Replied to Anyway To Fix Request()->validate Error: Array_map():Expected Parameter 2 To Be An Array, Int Given

trying to validate that the data from the view is exactly the value from that line. I just don't know how to write that. Something like 'required:value=2' but instead I would write as 'required:value='.Roles::customer()->firstOrFail()->id.''; I know that my db will have the correct int value, but my view might not so I need like a fail safe. Something that will fail should the wrong input be submitted. From the docs I can see that required has a value option, but I don't know how to write the code the right way. Keep running into errors.

Jul
08
4 months ago
Activity icon

Started a new Conversation Anyway To Fix Request()->validate Error: Array_map():Expected Parameter 2 To Be An Array, Int Given

    private function validateRequest()
    {
        return request()->validate([
            'name' => 'required|min:3',
            'role_id' => Roles::customer()->firstOrFail()->id,
        ]);
    }

So I have this code and I realize why it's failing, but I can't figure out how I can re-write this to make it work. Should I try typecasting it? Does anyone have an idea how to fix this? It would help me avoid some messy looking code and having to create 2 customer objects.

Activity icon

Replied to Eloquent Get Id Based On Where Clause

I was looking for that in the docs, but in the wrong spot. Thanks again!

Activity icon

Replied to Eloquent Get Id Based On Where Clause

Thank you so much! When you get a chance would you mind explaining why it works like that and mine failed?

Activity icon

Started a new Conversation Eloquent Get Id Based On Where Clause

I'm trying to get the id from a table based on a where clause condition. The sql query is pretty simple, but I keep getting errors no matter how I try this.

I've tried the following 3 ways

$customer->role_id = Roles::where('role', 'customer')->pluck('id'); // tried this with ->get(); too
//error from above:
//SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '[2]'

$customer->role_id = $role->where('role','customer')->pluck('id'); // tried this with ->get(); too
//error from above:
//SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '[2]'

$customer->role_id = DB::query("SELECT id FROM roles WHERE role = ?", ['customer']);
//error from above:
//Object of class Illuminate\Database\Query\Builder could not be converted to string 

The query works in sql and returns the right value. How can I fix this problem? I don't know how to use the right syntax for it.

Jul
02
4 months ago
Activity icon

Replied to The GET Method Is Not Supported For This Route. Supported Methods: POST.

I'm still trying to wrap my head around how MVC works. I'm trying to show a view when the nav link is clicked, but it needs to replace everything else so I can use a post method in another form that the user would input and submit. I thought I could use the store method for that since the convention is to use POST for it, but now I realize that should only be used after the user provides input and clicks submit. So I'll have to change that, but I don't know what to use for another view because I'm already using create. What would you suggest? Is create suppose to be the logic for all of the views in my controller? Should I have a controller for each view or can I have one controller that manages multiple views? So for example, I have a page and the user can select nav links on that page that will display other views. They are all functions of the same page/controller. So Accounts page will have things like make account, delete account, edit account, restore account, and so on. Should create method be used to display each view depending on which option a user clicks on? Or do I use the show method for that? This is all very new to me, thank you for your help.

Activity icon

Replied to The GET Method Is Not Supported For This Route. Supported Methods: POST.

That fixed the error, but it doesn't look like it's getting to the if condition because the page doesn't load.

@if(request()->is('store'))
            @include('accounts.store')
        @else

@michaloravec

Activity icon

Started a new Conversation The GET Method Is Not Supported For This Route. Supported Methods: POST.

I can't figure out how to fix this problem. I have a nav link which should load another view when it's clicked. Instead I get this message.

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: POST.
http://127.0.0.1:8000/accounts/store 

Here's the nav link code:

<a class="nav btn-outline-primary text-left nav-link {{ (request()->is('store')) ? 'active' : '' }}"
               href="{{route('accounts.store')}}" name="add" id="add">Make New Customer</a>

Here is my routes: (Note: accounts.store was being used as a get before and the method was just called accounts.add and used [email protected] Everything was working, but I don't want to use GET method in that form and need to use post instead. When I changed it to the following everything broke.)

Route::get('accounts/create', '[email protected]')->name('accounts.create');
Route::post('accounts/store', '[email protected]')->name('accounts.store');

Here is my controller:

    public function create()
    {
        return view('accounts.create');
    }

    public function store()
    {
        return redirect('accounts');
    }

the create.blade.php has this code in it.

@if(request()->is('store'))
            @include('accounts.store')
        @else
        <div class="col-sm">
            <form action="{{route('accounts.create')}}" method="GET" class="pb-15" autocomplete="off">
                @include('accounts.sidebar')
            </form>
        </div>
        <div class="col-sm-9">
            <form action="{{route('accounts.create')}}" method="GET" class="pb-15" autocomplete="off">
		{{--TODO--}}
            </form>
        </div>
        @endif

Any idea where I went wrong with this? Also if you need more info please let me know, thank you.

Jul
01
4 months ago
Activity icon

Replied to How To Handle Views With Nav-link Or Navs And Get A Neat URL?

I just realized it after my post, thank you.

Activity icon

Started a new Conversation How To Handle Views With Nav-link Or Navs And Get A Neat URL?

I'm trying to display my add.blade.php view, but only when the user clicks on a nav link for it. It's working so far, but with one problem. The url is messed up.

This code shows the view after the nav link is clicked:

@if(request()->is('add'))
	@include('accounts.add')
@endif

Here's my nav link:

<a class="nav text-left nav-link {{ (request()->is('add')) ? 'active' : '' }}"
               href="{{route('accounts.add')}}" name="add" id="add">Add</a>

When they click it I get the add.blade.php view, but my url changes to /add instead of accounts/add.

Here's what my web.php looks like.

Route::get('accounts', '[email protected]')->name('accounts.create');
Route::get('add', '[email protected]')->name('accounts.add');

How can I fix this so the url either stays as accounts or accounts/add?

Activity icon

Replied to How To Prevent From A Table Being Drop In Laravel

Yes, in sql you can drop an empty table as long as another table is not referencing it as foreign key. I'm assuming this table is not being used by another table since he was able to drop it without the foreign key constraint error. Thanks @snapey I forgot to clarify that part.

Activity icon

Replied to How To Prevent From A Table Being Drop In Laravel

That's the right way to make a table with a foreign key constraint. I'm assuming you have no data in the table. If yes, the reason you are able to drop the table without problems is because it's empty. If you actually populate it with some data with a foreign key using php artisan tinker than sql will give you a foreign key constraint error when you try to drop the table. If you actually go into sql and use describe operations; find your foreign key row and you should see | MUL | under the | Key | column that is sql's way of saying it's a foreign key.

edit: in sql you can drop an empty table as long as another table is not referencing it as foreign key.

To answer your question, you could create another empty table that will reference your table with foreignId('operation_id')->nullable(). That will prevent it from being dropped and the other table can remain empty the entire time with the nullable.

Activity icon

Replied to Will Update PHP 7.3 To 7.4 Break Anything?

I believe PHP 7.3 -> 7.4 had mostly performance enhancements. To be safe do what @martinbean suggested, sandbox the project and test it out.

Activity icon

Replied to Please Help With Views, Need Some Guidance And Help

Yes, I did. Thank you again. So I replaced @if(session()->has('add')) with @if(request()->has('add')) and that works. I can see the view when I click the button.

Activity icon

Replied to Please Help With Views, Need Some Guidance And Help

are you kidding me... LOL. That fixed it. Any idea how I can get my other view to show up? Nothing is happening after I click the add button. Thanks btw!

Activity icon

Started a new Conversation Please Help With Views, Need Some Guidance And Help

I could really use some help with this. I'm making a page where I want the user to manage accounts. They have a sidebar with options like add account etc. I have a button name="add" and the idea is to produce another view on click which would allow them to add an account. I'm not using the onclick="", but I'm instead using request()->has('add'). My understanding is that this will use a get request to see if the button click was sent to the server and if that's true I'm using @if condition to display another view.

Let me quickly explain the code here. I have 2 forms in my create.blade.php. The first form (GET) has the sidebar inside of it and the second form (POST) will produce views based on the if conditions than POST will be used to take the user input into the db. Right now I'm just doing the first button which is to add an account. So when I wrote this code, I'm thinking that I will call the route helper to access accounts.create inside the action. This is the main view and should be blank until the user clicks a sidebar button to present other views.

<div class="col-sm">
            <form action="{{route('accounts.create')}}}" method="get" class="pb-15" autocomplete="off">
                @include('accounts.sidebar')
            </form>
        </div>
        <div class="col-sm-9">
            <form action="{{route('accounts.create')}}}" method="post" class="pb-15" autocomplete="off">
                @if(session()->has('add'))
                    @include('accounts.add')
                @endif
            </form>
        </div>

My controller has a simple return function:

    public function create()
    {
        return view('accounts.create');
    }

My web.php looks like this:

Route::get('accounts', '[email protected]')->name('accounts.create');

When I click on the add button I get a 404 and the url looks oddly like this:

http://127.0.0.1:8000/accounts}?add=&q=

that q is from a search function I was working on, but didn't finish yet. That shouldn't be showing up unless I click on the search button so for some reason everything is getting requested. I'm sure I messed this up royally somewhere and somehow I just don't get it, but hopefully you do and can help me fix this.

Any help would be nice, thank you.

Jun
30
4 months ago
Activity icon

Replied to Move_uploaded_file Gives “failed To Open Stream: Permission Denied” Error

It's a permissions problem so you have to figure out which file needs to have permissions changed. You can check this solution as a reference.

https://stackoverflow.com/questions/8103860/move-uploaded-file-gives-failed-to-open-stream-permission-denied-error

Jun
26
5 months ago
Activity icon

Replied to Some HTML Help With Nav Bar And Side Bar

for anyone that's curious what the end result is... this is my create.blade.php with the sidebar included.

@section('content')
    <div class="container" style="margin-top:30px">
        <div class="row">
            <div class="col-sm-2.5">
                <h1>Accounts</h1>
                <h3>Options:</h3>
                <p></p>
                <ul class="nav nav-pills flex-column">
                    <li class="nav-item">
                        <a class="nav-link active" href="#">Add Account</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link danger" href="#">Delete Account</a>
                    </li>
                </ul>
                <hr class="d-sm-none">
            </div>
            <div class="col-sm-8">
                <form action="accounts" method="get" class="pb-15" autocomplete="off">
                    @include('accounts.search')
                    <button type="submit" class="btn btn-primary">Search</button>
                </form>
            </div>
        </div>
    </div>
@endsection

I ended up using the bootstrap tutorial inside of my accounts view. Now I have the sidebar appearing under the nav bar and I can include or yield for more content as the page develops.

Thanks for the help!

Activity icon

Replied to Some HTML Help With Nav Bar And Side Bar

Thanks that bootstrap4 tutorial is really helpful.