Updating laravel controller snippet to include session flashing
This commit is contained in:
		@@ -33,9 +33,11 @@ public function store(Request \$request)
 | 
				
			|||||||
    // assign model fields
 | 
					    // assign model fields
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (\$${3:model}->save()) {
 | 
					    if (\$${3:model}->save()) {
 | 
				
			||||||
 | 
					        \$request->session()->flash('status', "Successfully added {\$${3:model}->${4:field}}.");
 | 
				
			||||||
        return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully added {\$${3:model}->${4:field}}.");
 | 
					        return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully added {\$${3:model}->${4:field}}.");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \$request->session()->flash('error', 'Unable to save that ${3:model}.');
 | 
				
			||||||
    return redirect()->back()->with('error', 'Unable to save that ${3:model}.');
 | 
					    return redirect()->back()->with('error', 'Unable to save that ${3:model}.');
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -53,19 +55,23 @@ public function update(Request \$request, ${1:MODEL} \$${3:model})
 | 
				
			|||||||
    // assign model fields
 | 
					    // assign model fields
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (\$${3:model}->update()) {
 | 
					    if (\$${3:model}->update()) {
 | 
				
			||||||
 | 
					        \$request->session()->flash('status', "Successfully updated {\$${3:model}->${4:field}}.");
 | 
				
			||||||
        return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully updated {\$${3:model}->${4:field}}.");
 | 
					        return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully updated {\$${3:model}->${4:field}}.");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \$request->session()->flash('error', "Unable to update {\$${3:model}->${4:field}}.");
 | 
				
			||||||
    return redirect()->back()->with('error', "Unable to update {\$${3:model}->${4:field}}.");
 | 
					    return redirect()->back()->with('error', "Unable to update {\$${3:model}->${4:field}}.");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public function destroy(${1:MODEL} \$${3:model})
 | 
					public function destroy(Request \$request, ${1:MODEL} \$${3:model})
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    \$${4:field} = \$${3:model}->${4:field};
 | 
					    \$${4:field} = \$${3:model}->${4:field};
 | 
				
			||||||
    if (\$${3:model}->delete()) {
 | 
					    if (\$${3:model}->delete()) {
 | 
				
			||||||
 | 
					        \$request->session()->flash('status', "Successfully removed {\$${4:field}}.");
 | 
				
			||||||
        return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully removed {\$${4:field}}.");
 | 
					        return redirect()->route('dashboard.${2:models}.index')->with('status', "Successfully removed {\$${4:field}}.");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    \$request->session()->flash('error', "Unable to remove {\$${4:field}}.");
 | 
				
			||||||
    return redirect()->back()->with('error', "Unable to remove {\$${4:field}}.");
 | 
					    return redirect()->back()->with('error', "Unable to remove {\$${4:field}}.");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
]]></content>
 | 
					]]></content>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user