hootlex / laravel-friendships

This package gives Eloquent models the ability to manage their friendships.
MIT License
703 stars 151 forks source link

laravel issue when I add notes to database #126

Open IAmShawky opened 5 years ago

IAmShawky commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.