Skip to content

Instantly share code, notes, and snippets.

View minthemiddle's full-sized avatar

Martin minthemiddle

View GitHub Profile
@minthemiddle
minthemiddle / Markdium-HTML.html
Created July 9, 2020 20:14
Markdium-How to use AlpineJS with Laravel Mix
<div x-data="{ open: false }">
<button @click="open = true">Open Dropdown</button>
<ul
x-show="open"
@click.away="open = false"
>
Dropdown Body
</ul>
</div>
@minthemiddle
minthemiddle / Markdium-HTML.html
Created July 9, 2020 20:12
Markdium-Laravel Forms 101
<!-- Blade, e.g. welcome.blade.php -->
<form action="{{ route('form.submit') }}" method="POST" class="space-y-4">
@csrf
<div>
@error('fullname')
<div class="text-red-500">{{ $message }}</div>
@enderror
<label for="fullname">Fullname</label>
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:12
Markdium-Laravel Forms 101
// routes/web.php
validate([
'fullname' => 'required|alpha|min:3',
]);
return 'Submission allowed';
})->name('form.submit');
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:09
Markdium-Lessons Learnt: PHPUnit for Beginners
public function handle($request, Closure $next)
{
if (! auth()->user()->is_admin)
{
abort(403);
}
return $next($request);
}
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:09
Markdium-Lessons Learnt: PHPUnit for Beginners
private function create_user(is_admin = 0)
{
$this->user = factory(User::class)->create([
'is_admin' => $is_admin,
]);
}
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:09
Markdium-Lessons Learnt: PHPUnit for Beginners
$response = $this->post('login', [
'email' => 'EMAIL',
'password' => 'PW'
]);
// assert where you expect to be redirected to, e.g. home
$response->assertRedirect('/home');
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:09
Markdium-Lessons Learnt: PHPUnit for Beginners
public rules() {
return [
'name' => 'required',
'price' => 'required',
];
}
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:09
Markdium-Lessons Learnt: PHPUnit for Beginners
public function destroy(Product $product) {
$product->delete();
return redirect()->route('products.index');
}
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:09
Markdium-Lessons Learnt: PHPUnit for Beginners
id) }} method="POST" onsubmit="confirm('Sure?')">
@minthemiddle
minthemiddle / Markdium-Hack.php
Created July 9, 2020 20:09
Markdium-Lessons Learnt: PHPUnit for Beginners
$response = $this->actingAs($this->user)
->put('/products/' . $product->id,
[
'name' => 'Test',
'price' => 99.99,
],
[
'Accept' => 'Application/json',
]);