app/Http/Controllers/ConversationController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $request->validate([
            'user_id'=>'required',
            'message'=>'required'
        ]);
        $conversation = Conversation::create([
            'user_id'=>auth()->user()->id ,
            'second_user_id'=>$request['user_id']
        ]);
        $conversation = Conversation::create([
            'user_id'=>auth()->user()->id ,
            'second_user_id'=>$request['user_id']
        ]);
        $message = Message::create([
            'body'=>$request['message'],
            'user_id'=>auth()->user()->id ,
            'conversation_id'=>$request['user_id'],
            'read'=>false
    ]);
        return new ConversationResource($conversation);
    }
public function store ( Request $ request ) { $ request -> validate ( [ 'user_id' => 'required' , 'message' => 'required' ] ) ; $ conversation = Conversation :: create ( [ 'user_id' => auth ( ) -> user ( ) -> id , 'second_user_id' => $ request [ 'user_id' ] ] ) ; $ conversation = Conversation :: create ( [ 'user_id' => auth ( ) -> user ( ) -> id , 'second_user_id' => $ request [ 'user_id' ] ] ) ; $ message = Message :: create ( [ 'body' => $ request [ 'message' ] , 'user_id' => auth ( ) -> user ( ) -> id , 'conversation_id' => $ request [ 'user_id' ] , 'read' => false ] ) ; return new ConversationResource ( $ conversation ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .