The post command alias list , massive time saver appeared first on Site Builder Studio.
]]>In cmder / conEmu , go to settings > startup > environment , you can add alias list there or directly to the user_aliases.cmd file. Here’s some ideas ( or free to steal ) for git and laravel shorthand. Have fun!
gs=git status
ga=git add .
gc=git commit -m "$*"
gpush=git push
gpull=git pull
art=php artisan
migrate=php artisan migrate
tinker=php artisan tinker
serve=php artisan serve
mm=php artisan make:migration
mfs=php artisan migrate:fresh --seed
mc=php artisan make:controller
mrc=php artisan make:controller --resource
paoc=php artisan optimize:clear
mt=php artisan make:test
mtu=php artisan make:test --unit
cdo=composer dump-autoload -o
ci=composer install
cu=composer update
co=composer outdated
nah=git reset --hard && git clean -df
wip=git add . && git commit -m "wip"
The post command alias list , massive time saver appeared first on Site Builder Studio.
]]>The post WordPress Optimization appeared first on Site Builder Studio.
]]>Keep your visitors attention by never making them wait!
It’s worth the effort.
When looking to optimize your WordPress site, here are the main things you should be considering; quality of host, efficiency of theme, cache, CDN (Content Delivery Network, so your images, css, js files are loaded from a server near the visitor), GZip compression, well coded plugins, optimization of the database, properly sized uploaded images, deletion of unneeded post revisions, spam reduction, turn off pingbacks, css in head js in body, and using a responsive design.
As you can see there are many things you can do to increase the load time of your WordPress site. You might want to contact us to conduct these optimizations for you. Each element is tricky and it can be a daunting mission!
It takes time to get your WordPress site optimized to load quickly, but that is time that your visitors will save when viewing your site.
The post WordPress Optimization appeared first on Site Builder Studio.
]]>The post Granular permissions in Laravel appeared first on Site Builder Studio.
]]>Enter Granular Project-Based Permissions—a refined system for access control. It’s designed for applications that demand permissions to be discerned not just by user roles but intricately tailored to specific contexts or projects.
In this tutorial, we’ll utilize a project management system as our foundational example to illustrate the potential of this enhanced permission system. By harnessing the Spatie’s permissions package, coupled with Laravel’s robust Eloquent and the dynamic capabilities of Livewire, we will construct an adaptable permission matrix that evaluates both user permissions and their specific project context.
But remember, while our example centers on a project management paradigm, the essence of this guide is adaptability. Whether your next venture is a niche-specific SaaS, an intricate CRM, or a groundbreaking platform yet to be imagined, the techniques illustrated here can be adjusted and scaled to your unique requirements. Dive in, and discover the potential of truly granular permissions in Laravel.
Granular permissions
This solution integrates Spatie’s permissions for a granular, project-specific permission system. The combination of the Spatie package with this custom relationship allows for both general role/permissions and specific project permissions.
Setup Spatie Permissions
Here’s a list for starters, we’ll add more once the new permissions framework is in place.
create project
read project
update project
delete project
create task
read task
update task
delete task
Create project_user_permission table
1. **Enhance Database Structure**:
– Create a table called `project_user_permission` which will have the columns:
– `user_id`
– `project_id`
– `permission_id`
2. **Migrate the New Structure**:
Create a new migration:
php artisan make:migration create_project_user_permission_table
Inside this migration:
public function up() {
Schema::create(‘project_user_permission’, function (Blueprint $table) {
$table->unsignedBigInteger(‘user_id’);
$table->unsignedBigInteger(‘project_id’);
$table->unsignedBigInteger(‘permission_id’);
$table->foreign(‘user_id’)->references(‘id’)->on(‘users’)->onDelete(‘cascade’);
$table->foreign(‘project_id’)->references(‘id’)->on(‘projects’)->onDelete(‘cascade’);
$table->foreign(‘permission_id’)->references(‘id’)->on(‘permissions’)->onDelete(‘cascade’);
$table->unique([‘user_id’, ‘project_id’, ‘permission_id’]);
});
}
Add Method to User Model
public function hasProjectPermission($permissionName, $project) {
$permissionId = Spatie\Permission\Models\Permission::findByName($permissionName)->id;
return DB::table(‘project_user_permission’)
->where(‘user_id’, $this->id)
->where(‘project_id’, $project->id)
->where(‘permission_id’, $permissionId)
->exists();
}
Checking Permissions
To check if a user has the permission ‘edit tasks’ for a specific project:
$user->hasProjectPermission(‘edit tasks’, $specificProject);
In Blade:
@if($user->hasProjectPermission(‘edit tasks’, $specificProject))
<!– Display the edit button for tasks in that specific project –>
@endif
Managing Permissions
To grant a permission for a user on a specific project:
$permissionId = Spatie\Permission\Models\Permission::findByName(‘edit tasks’)->id;
DB::table(‘project_user_permission’)->insert([
‘user_id’ => $user->id,
‘project_id’ => $specificProject->id,
‘permission_id’ => $permissionId
]);
To revoke a permission:
$permissionId = Spatie\Permission\Models\Permission::findByName(‘edit tasks’)->id;
DB::table(‘project_user_permission’)
->where(‘user_id’, $user->id)
->where(‘project_id’, $specificProject->id)
->where(‘permission_id’, $permissionId)
->delete();
Permissions Management Page
Creating a Livewire page to manage permissions for users within a project will involve a few key steps. We’ll create:
1. A Livewire component to display users associated with a project and manage their permissions.
2. The Blade view for the component.
3. Necessary Livewire methods for interaction.
Let’s break it down step-by-step:
Creating a Livewire page to manage permissions for users within a project will involve a few key steps. We’ll create:
1. A Livewire component to display users associated with a project and manage their permissions.
2. The Blade view for the component.
3. Necessary Livewire methods for interaction.
Let’s break it down step-by-step:
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Project;
use App\Models\User;
use Spatie\Permission\Models\Permission;
class ManageProjectPermissions extends Component
{
public $project;
public $permissions;
public $users;
public $selectedUser; // For dropdown selection
public function mount(Project $project) {
$this->project = $project;
$this->permissions = Permission::all();
$this->users = $project->users;
$this->selectedUser = null;
}
public function addUserToProject() {
$user = User::find($this->selectedUser);
$this->project->users()->attach($user);
$this->users = $this->project->users; // Refresh users
}
public function removeUserFromProject($userId) {
$this->project->users()->detach($userId);
$this->users = $this->project->users; // Refresh users
}
public function updateUserPermission($userId, $permissionId, $value) {
$user = $this->users->find($userId);
if($value) {
// Grant permission
DB::table(‘project_user_permission’)->updateOrInsert([
‘user_id’ => $user->id,
‘project_id’ => $this->project->id,
‘permission_id’ => $permissionId
]);
} else {
// Revoke permission
DB::table(‘project_user_permission’)
->where(‘user_id’, $user->id)
->where(‘project_id’, $this->project->id)
->where(‘permission_id’, $permissionId)
->delete();
}
}
public function render() {
return view(‘livewire.manage-project-permissions’);
}
}
The post Granular permissions in Laravel appeared first on Site Builder Studio.
]]>The post WordPress Hacked appeared first on Site Builder Studio.
]]>Remember, security is an ongoing process. Regularly monitor, update, and backup your site to ensure it remains secure.
After a hack, checking logs can provide valuable insights into how the exploit occurred, what vulnerabilities were leveraged, and what actions the attacker took. Here’s a step-by-step guide on what logs to check and what to look for:
wp-config.php
file (though this is more for debugging purposes and less for security):php define('WP_DEBUG', true); define('WP_DEBUG_LOG', true);
Tips for Analyzing Logs:
Lastly, if you’re not familiar with log analysis or if the breach is severe, consider hiring SiteBuilderStudio to conduct a thorough investigation. They can provide a detailed analysis, help identify vulnerabilities, and offer recommendations for securing your site in the future.
The post WordPress Hacked appeared first on Site Builder Studio.
]]>The post Tools for Logging appeared first on Site Builder Studio.
]]>These tools can handle log files of various formats and sizes. Some also support tailing logs in real time, color coding, filtering and alerting – all of which can be very useful when working with large log files. Remember to always choose the tool that best fits your specific needs.
Searching log files by date range can be a useful way to analyze and troubleshoot issues. Below are some log viewers for Windows that support this feature:
While not all log viewers offer the ability to search by date range directly, you can often manually search or filter for date stamps, assuming your log entries are timestamped in a consistent format.
Remember, the log viewers listed above go beyond basic functionalities such as viewing and searching logs – they include a wide variety of features which can help you manage, parse, and analyze your log data. Choose the one that fits your requirements best.
The post Tools for Logging appeared first on Site Builder Studio.
]]>The post WordPress Development Tools appeared first on Site Builder Studio.
]]>Remember to always verify the compatibility and support of these plugins and packages with your current version of WordPress or PHP. Also, follow good practices while using them to maintain the security and performance of your WordPress websites.
The post WordPress Development Tools appeared first on Site Builder Studio.
]]>The post Stripe Update Subscription Price appeared first on Site Builder Studio.
]]>Three times now we’ve been hired to update subscription prices on Stripe for existing subscribers ( let’s face it, prices for most things are going up ). The basic strategy for doing this is as follows;
Call the Stripe API and update subscription price id.
Now I’m here imagining that in 2023 many companies are needing to update subscription price on Stripe for existing subscribers. Therefor, we’ve spun up an app that will handle this for you. Simple enter the price id you with to change, and the price id you wish to change it to. The app then makes the required API calls and updates subscription price on Stripe.
If you’re reading this part here right now, the app to update subscription price on Stripe is not fully setup for SaaS ( software as a service ), so if you’d like to use the tool please book a call.
If you only have a small amount of subscribers and wish to update the subscription price manually, the procedure is as follows.
1 > On the Stripe dashboard, create the new price on the corresponding product.
2 > Copy that price id from the price you’ve just created
3 > Go to each subscription that has the old price and replace it with the new.
But if it’s even worth doing, you’re probably doing it in bulk. Note, our tool can update as many price points as you have in your setup. We can also spin up any other Stripe API solution you may need.
The post Stripe Update Subscription Price appeared first on Site Builder Studio.
]]>The post In Laravel you can batch queries so each only executes if they all do appeared first on Site Builder Studio.
]]>DB
facade, which provides a simple interface for beginning, committing, and rolling back transactions. The beginTransaction
method is used to start a transaction, and the commit
method is used to commit the transaction. If an error occurs during the transaction, the rollBack
method can be used to roll back the transaction.
To use transactions in Laravel, you can wrap your database operations in a DB::transaction
block. If an exception is thrown within the transaction block, the transaction will automatically be rolled back.
Big picture example;
use Illuminate\Support\Facades\DB;
try {
DB::beginTransaction();
// Perform database operations here
DB::table('users')->update(['is_active' => 1]);
DB::table('logs')->insert(['message' => 'All users were activated']);
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
// Handle the exception
}
The cleaner way to write the same, commit and rollback will be automatic;
use Illuminate\Support\Facades\DB;
DB::transaction(function() {
DB::table('users')->update(['is_active' => 1]);
DB::table('logs')->insert(['message' => 'All users were activated']);
});
Now the message will only be written to log if the users are successfully updated to active. This is such a time saver and headache solver. One example use case – first create a user, then create a profile for that user, then setup a row in the billing/subscriptions table. With Laravel transactions we can avoid coding all the exception handling and if statements and make sure that either all these three things are setup or none are at all.
That’s Laravel db transactions.
The post In Laravel you can batch queries so each only executes if they all do appeared first on Site Builder Studio.
]]>The post Expose serves local webhook endpoints for dev/testing appeared first on Site Builder Studio.
]]>Similar to Ngrok, you can use expose.dev aka SharedWithExpose on you dev machine. Once installed just go to your sites main directory in the command line ( of course this must be running in a server environment ) , then simply use the command “expose share yourprojectname.test“.
Note if you get ‘could not connect to server’ try disabling your VPN.
The free version gives one hour sessions, we can either restart expose hourly or pay for the software.
The post Expose serves local webhook endpoints for dev/testing appeared first on Site Builder Studio.
]]>The post ShipStation API appeared first on Site Builder Studio.
]]><?php
// Set the API endpoint URL
$url = "https://ssapi.shipstation.com/orders/createorder";
// Set the API key and secret
$api_key = "YOUR_API_KEY";
$api_secret = "YOUR_API_SECRET";
// Set the order details
$order_data = array(
"orderNumber" => "12345",
"orderDate" => "2022-05-01T10:00:00",
"orderStatus" => "awaiting_shipment",
"shippingAmount" => 5.99,
"taxAmount" => 1.23,
"orderTotal" => 25.99,
"customerUsername" => "johndoe",
"customerEmail" => "johndoe@example.com",
"billTo" => array(
"name" => "John Doe",
"company" => "Acme Inc.",
"street1" => "123 Main St.",
"street2" => "Suite 100",
"city" => "Austin",
"state" => "TX",
"postalCode" => "78701",
"country" => "US",
"phone" => "555-123-4567"
),
"shipTo" => array(
"name" => "Jane Doe",
"company" => "Acme Inc.",
"street1" => "456 Elm St.",
"city" => "Austin",
"state" => "TX",
"postalCode" => "78701",
"country" => "US",
"phone" => "555-987-6543"
),
"items" => array(
array(
"sku" => "SKU123",
"name" => "Product 1",
"quantity" => 2,
"unitPrice" => 10.99,
"warehouseLocation" => "A1"
),
array(
"sku" => "SKU456",
"name" => "Product 2",
"quantity" => 1,
"unitPrice" => 3.99,
"warehouseLocation" => "B2"
)
)
);
// Convert the order data to JSON
$order_json = json_encode($order_data);
// Create a cURL handle
$ch = curl_init();
// Set the cURL options
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $order_json,
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"Authorization: Basic " . base64_encode($api_key . ":" . $api_secret)
)
));
// Execute the cURL request
$response = curl_exec($ch);
// Check for errors
if (curl_errno($ch)) {
echo "Error: " . curl_error($ch);
} else {
echo $response;
}
// Close the cURL handle
curl_close($ch);
?>
The post ShipStation API appeared first on Site Builder Studio.
]]>