app/Http/Controllers/TasksController.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)
    {   
        $this->validate($request, [
            'company' => 'required', 
            'title' => 'required',
            'assigned_to' => 'required',
            'priority' => 'required',
            'image.*' => 'mimes:jpg,jpeg,png|max:2000'
          ],[
            'image.*.mimes' => 'Only jpeg, png, jpg images are allowed',
            'image.*.max' => 'Sorry! Maximum allowed size for an image is 2MB',
        ]);
        $task = new Task();
        $task->title = $request->title;
        $task->description = $request->description;
        $task->department = $request->department;
        $task->assigned_to = json_encode($request->assigned_to);
        $task->contact_person = $request->contact_person;
        $task->priority = $request->priority;        
        $task->company = $request->company;
        if($request->hasFile('image'))
        {
            foreach($request->file('image') as $image) 
            {
                $filename = $image->getClientOriginalName();
                $image->storeAs('tasks', $filename);
                $imgData[] = $filename;
            }
            $task->image = json_encode($imgData);
        }
        $task->save();
       session()->flash('success', 'Task Created successfully'); 
       $completed = Task::select('*')
       ->where('completed', '=', 0)
       ->orderBy('priority', 'asc')
       ->orderBy('updated_at', 'DESC')
       ->get();
       return view('project.index')->with('companies', Company::all())->with('users', User::all())->withTasks($completed);
    }
public function store ( Request $ request ) { $ this -> validate ( $ request , [ 'company' => 'required' , 'title' => 'required' , 'assigned_to' => 'required' , 'priority' => 'required' , 'image.*' => 'mimes:jpg,jpeg,png|max:2000' ] , [ 'image.*.mimes' => 'Only jpeg, png, jpg images are allowed' , 'image.*.max' => 'Sorry! Maximum allowed size for an image is 2MB' , ] ) ; $ task = new Task ( ) ; $ task -> title = $ request -> title ; $ task -> description = $ request -> description ; $ task -> department = $ request -> department ; $ task -> assigned_to = json_encode ( $ request -> assigned_to ) ; $ task -> contact_person = $ request -> contact_person ; $ task -> priority = $ request -> priority ; $ task -> company = $ request -> company ; if ( $ request -> hasFile ( 'image' ) ) { foreach ( $ request -> file ( 'image' ) as $ image ) { $ filename = $ image -> getClientOriginalName ( ) ; $ image -> storeAs ( 'tasks' , $ filename ) ; $ imgData [ ] = $ filename ; } $ task -> image = json_encode ( $ imgData ) ; } $ task -> save ( ) ; session ( ) -> flash ( 'success' , 'Task Created successfully' ) ; $ completed = Task :: select ( '*' ) -> where ( 'completed' , '=' , 0 ) -> orderBy ( 'priority' , 'asc' ) -> orderBy ( 'updated_at' , 'DESC' ) -> get ( ) ; return view ( 'project.index' ) -> with ( 'companies' , Company :: all ( ) ) -> with ( 'users' , User :: all ( ) ) -> withTasks ( $ completed ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//upload the image to the storage