Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

laravel issue when I add notes to database #126

Open
IAmShawky opened this issue Apr 18, 2019 · 3 comments
Open

laravel issue when I add notes to database #126

IAmShawky opened this issue Apr 18, 2019 · 3 comments

Comments

@IAmShawky
Copy link

Hi, I am working on laravel project it has 2 tables in DB, one for "pages" and other for "notes" I am making 2 models n 2 controllers and I'm connecting the tables using one2many relation, "one page which has many notes". I made 2 views in blade files. one to show all the titles of all pages, I already have inserted title column in DB which refers to the title of page, on other table of notes, I used column of text, and i put another column as a foreign key called page id n i inserted the same value of the auto increment id in pages table, i post the functions in both models and from my experiment everything until nw is working fine, except the part of insertion of the note, it gives me errors, I believe the problem might be from route or notecontroller, I will post some codes down there:
show all pages
show one page
the error
note controller
note model
page controller
page model
show all pages blade
show one page has many notes

@heidilux
Copy link

heidilux commented Apr 18, 2019

This is not an issue with this friendships package, but you're calling pages() on your Page model in your PostGeneralNote() method. You have a page() method on your Notes mode, or a note() method on your Page model.

you probably want something like:

$note->page_id = $id_page->id;
$note->save();

@IAmShawky
Copy link
Author

can u write me the full correct code, for notecontroller? and i am kindly asking u since i am new here, how to post individual issue on github site?

@heidilux
Copy link

I would do something like this

public function postGeneralNote(Request $request, Page $page) {
    $note = new Note;
    $note->text = $request->get('note_text');
    $note->save();

    $page->note_id = $note->id;
    $page->save();

    return back();
}

I would spend a bit of time in the Laravel docs, and/or take a visit to laracasts. There are some great "getting started with Laravel" videos there that don't require a paid subscription.

Also, if you have further questions, I would use stackoverflow, or the laracasts forums. Github should be for issues with the individual packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants