forked from ludoguenet/laranudge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab7a3f6
commit d28f134
Showing
23 changed files
with
657 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Admin\Nudge; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Nudge; | ||
use Illuminate\Contracts\View\View; | ||
|
||
class EditController extends Controller | ||
{ | ||
public function __invoke(Nudge $nudge): View | ||
{ | ||
return view('nudges.edit', [ | ||
'nudge' => $nudge, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Admin\Nudge; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\Nudge; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
|
||
class UpdateController extends Controller | ||
{ | ||
/** | ||
* Handle the incoming request. | ||
*/ | ||
public function __invoke(Nudge $nudge, Request $request): RedirectResponse | ||
{ | ||
$validated = $request->validate([ | ||
'title' => ['required', 'unique:nudges,title,'.$nudge->id, 'max:100'], | ||
'content' => 'required|string|max:500', | ||
'code' => 'required|string', | ||
]); | ||
|
||
$nudge->update($validated); | ||
|
||
return redirect()->route('admin.index'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Nudge; | ||
|
||
use App\Actions\Nudge\GenerateRandomSynonym; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Nudge; | ||
use Illuminate\Contracts\View\View; | ||
|
||
class ShowController extends Controller | ||
{ | ||
public function __invoke(Nudge $nudge): View | ||
{ | ||
abort_if(! $nudge->validated, 404); | ||
|
||
$randomSynonym = (new GenerateRandomSynonym)->handle(); | ||
|
||
return view('nudges.show', [ | ||
'nudge' => $nudge->loadCount('likes'), | ||
'randomSynonym' => $randomSynonym, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
database/migrations/2024_03_07_210642_add_title_to_nudges.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('nudges', function (Blueprint $table) { | ||
$table->string('title', 100)->unique()->nullable(); | ||
}); | ||
|
||
DB::table('nudges') | ||
->update([ | ||
'title' => DB::raw("('nudge-' || id)"), | ||
]); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('nudges', function (Blueprint $table) { | ||
$table->dropUnique(['title']); | ||
$table->dropColumn('title'); | ||
|
||
}); | ||
} | ||
}; |
37 changes: 37 additions & 0 deletions
37
database/migrations/2024_03_07_210649_add_slug_to_nudges.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('nudges', function (Blueprint $table) { | ||
$table->string('slug')->unique()->nullable(); | ||
}); | ||
|
||
DB::table('nudges') | ||
->update([ | ||
'slug' => DB::raw("('nudge-' || id)"), | ||
]); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('nudges', function (Blueprint $table) { | ||
$table->dropUnique(['slug']); | ||
$table->dropColumn('slug'); | ||
}); | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.